Calling a python function from MATLAB, generates an object with only some attribute - matlab

From MATLAB I am calling a Python function that creates and returns a Python object MyPyObj created by me with some attribute. The object is correctly returned however some attribute is missing and when I try to access them in MATLAB, a No appropriate method, property, or field error is returned. Does someone know why this happens?

Have you already tried this:
commandStr = 'python /Users/myName/pathToScript/sqr.py 2';
[status, commandOut] = system(commandStr);
if status==0
fprintf('squared result is %d\n',str2num(commandOut));
end

I managed to solve the problem following this post. Basically I needed to use
py.getattr(myPyObj, 'name_of_the_hidden_attribute')
However I am still not able to understand why myPyObj.name_of_the_hidden_attribute throws an error. I want to provide also this link in case my solution does not fix the problem for other users.

Related

Node.CloneNode() not a function -dom-to-image.js

I want to create a .png file of a HTML page in angularjs and download it. For this I'm currently using dom-to-image.js and using the domToImage.toBlob function and passing the node element to it. But internally when it goes to dom-to-image.js it throws the error:
node.cloneNode() is not a function
Can anyone please assist me here?
Thanks
This error arises when you attempt to call cloneNode() on anything other than a single DOM node.
In this case, the error is coming from the dom-to-image library, which calls that method internally.
Note that without a code snippet, its hard to identify the precise issue with your code, but the point is, when you call domtoimage.toBlob(), you need to supply a single DOM node.
So double check what you are calling it with. If you are selecting by class, for instance, you could end up with more than one element.
Its best practice to be precise with which node you want to convert to a blob - use the id attribute, like this:
domtoimage.toBlob(document.getElementById('element')).then(...)
where element is the id of your target node.
Its also possible you're selecting with angular.element() or even using jQuery directly.
In both cases, this returns an Object -- which you can't call cloneNode() on.
Also note the following from the Angular docs for angular.element():
Note: All element references in AngularJS are always wrapped with jQuery or jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.
Which means you would observe the same behavior in both cases, e.g. both of these:
domtoimage.toBlob($('#element')).then(...)
domtoimage.toBlob(angular.element('#element')).then(...)
would result in the error you see. You can index the Object before supplying it to domtoimage.toBlob(), perhaps like this:
domtoimage.toBlob($('#element')[0]).then(...)
domtoimage.toBlob(angular.element('#element')[0]).then(...)
and that would also work.
Also check out this post about "cloneNode is not a function".

Error "Function 'subsindex' is not defined for values of class 'embedded.fi'." When Changing Matlab Version

I have a struct 'ss' in Matlab that has a number of fields that are all zero'd in the beginning.
Declarations:
ss = struct;
ss.angle_spit = zeros(ais,his,tis,2);
ss.angle_neck = zeros(ais,his,tis,2);
I then go into a for loop and each iteration I update these values like such.
ss.angle_spit(ai,hi,fi,ti,1) = angle_spit_d;
ss.angle_spit(ai,hi,fi,ti,2) = angle_spit_u;
I was running this code on Matlab version R2015a with no errors, however, when I started to run it on a different computer running R2012a it gives me the error
"Error using subsindex
Function 'subsindex' is not defined for values of class 'embedded.fi'.
Error in spit_additup_11a_for12long3_fixqs (line 409)
ss.angle_spit(ai,hi,fi,ti,1) = angle_spit_d;"
My understanding is that I am trying to index the struct and that is not a possibility in 2012 and it is in 2015. Am I correct in assuming this, and if so, how would you go about changing the code to support this in 2012? Would you just create many more fields for the struct? Thank You.
I think the problem is that you are creating an index variable called fi and it's being confused with the function fi from the Fixed-Point Designer. When you try to use it as an index into the structure field ss.angle_spit, it throws the given error. The version-dependence of the error is more likely a dependence on whether the Fixed-Point Designer is included with your installation or not.
Try renaming fi to something else. I would expect that to fix the problem.
On a broader note, you should avoid giving variables the same name as an existing function, since it can either shadow that function or lead to strange behavior like you're seeing. As such, you should also rename your structure variable, since ss is already an existing function.

Can not add function to mongodb

I don't know when the problem begin. I find that when i create a new function to mongodb, and then run it like this:
db.loadServerScripts();
testFun('xxx');
Two errors will occur:
SyntaxError: missing } after property list src/mongo/shell/db.js:1038
ReferenceError: testFun is not defined (shell):1
But the old functions work fine. And when I delete one old function, and recreate it without anything changed, it also results in the same error above.
The version of mongodb I used is 2.6.10.
I think I have found the answer to this question. The error was cased by some other function. The error message puzzled me , I used to think that it must be an error from the mongo itself. I delete some mongo function written by me, and then the error was missing. Now I can run testFun successfully.

Zend Navigation - setParent Zend_Navigation_Container

Currently working on some modifications inside a Zend Framework website. One of the things I've been trying to change is the navigation structure and caching of the website. Unfortunate I've came accros a small problem which I, for some reason, cant figure out.
The problem is that I've build up a multi dimensional tree structured array from a database, which I want to pass on to the Zend Navigation class. To me, the array seems legit but Zend throws back the setParent error 'Argument 1 passed to Zend_Navigation_Page::setParent() must be an instance of Zend_Navigation_Container, string given'.
After some debugging and research, I've found a test array (pastebin array) and pasted this in as the first argument array. The array looks (as far I can see) almost the same as my generated array (pastebin array).
I hope someone can help me move on with this problem.
Best regards.
Found the problem. Thanks to the 'test array' I've added variables from my generated array one by one. After adding the $row['parent'] variable, the 'test array' also crashed into the setParent error.
foreach($elements as $key => $value) {
$leaf = $value
$value['swag'] = $value['parent'];
unset($value['parent']);
}
Code above is not the exact code used, just the snippet which fixed this bug.
You need to make sure that your array that you are sending to setParent is an instance of Zend_Navigation_Container.
First paste your array through Zend_Navigation() then paste the Instance through the setParent function of Zend_Navigation_Page.

matlab dbstop syntax error

So I have a class in an #file being referenced by a file in the root directory. a couple of the methods in the # file are in separate m files as function. It seems at times. but when I try and set a breakpoint in any of the methods I get an error "cannot enable breakpoints because of syntax error. Error using ==>dbstop. cannot find function C:/../methodname.m" I run the file anyways. It gives an error "No appropriate method, property, or field methodName for class className". But when I type in "methods(classname)" my method name is clearly listed there. I have a constructor:
function obj = ClassName(input) % constructor
obj.Input = input;
end
This is being registered and I can access all of my property values. My function definitions pass in "obj" as the first argument. There doesn't seem to be any indication of a syntax error and even though the method is clearly being recognized, it doesn't seem to be recognized at runtime. so really 2 different problems but I imagine they are linked. has anyone else had a similar issue? one of the function definitions looks like
function result = MethodName(obj,var1,var2)
....
end
Thanks a ton in advance guys. it's a pretty vague issue. Is there any other information I can provide that would help? matlab version is R2009a.