Prev: "figure properties" Java exception on Linux
Next: MATLAB Builder NE: Error using ==> getKnot Too many output arguments
From: Shashank Sawant on 14 Apr 2010 21:54 There's an m file which if I run through the editor (by clicking the play button) runs perfectly, but when called from the command window, gives the error: ??? Attempt to reference field of non-structure array. How do I get rid of this error?
From: us on 14 Apr 2010 23:31 "Shashank Sawant" <sgsawant(a)gmail.com> wrote in message <hq5rjr$i09$1(a)fred.mathworks.com>... > There's an m file which if I run through the editor (by clicking the play button) runs perfectly, but when called from the command window, gives the error: > ??? Attempt to reference field of non-structure array. > > How do I get rid of this error? how can you possibly assume that CSSMers would have any solution to your idiosyncratic problem given the above, completely useless information(?).... us
From: Walter Roberson on 15 Apr 2010 01:21
Shashank Sawant wrote: > There's an m file which if I run through the editor (by clicking the > play button) runs perfectly, but when called from the command window, > gives the error: > ??? Attempt to reference field of non-structure array. > > How do I get rid of this error? You are using eval() or assignin() or load() to "poof" a variable into existence, probably under the same name as an existing variable or function. When you run by pressing the 'play' button, Matlab does not attempt to compile the file and just runs it line by line, and so catches that the new value exists. When you call the file from the command line, then Matlab compiles the file first, and sees the original value of the variable but does not know at compile time that eval() or load() or what-ever will create the variable, so when it compiles, it compiles the following references as being references to the version of the variable or function that it knows about. The best solution for this is not to "poof" variables into existence, and not to use variable names that are the same as any function name. This advice includes not just using load(FileName), but instead using something like StructureName = load(FileName); and then referencing the fields of StructureName instead of having the variables from the file "just appear" in the workspace. If you for some reason _must_ use eval() or assignin() or the like, then before the call that will assign to the variable, if the variable name is static, assign to the variable a skeleton of a similar data class, so that Matlab will know at compile time that the variable exists and will know what it can do with that kind of variable. If you are creating dynamic variable names and thus cannot give that static clue to the Matlab compiler, then chances are good that you should redesign what you are doing, as there will almost always be a better way (e.g., dynamic field names for structures.) |