Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: Adding Arrays Together
Posted:
Mar 6, 2013 9:48 AM
|
|
"S Stron" <ss708@york.ac.uk> wrote in message news:kh6vdc$kll$1@newscl01ah.mathworks.com... > Yeah the only problem is they aren't my variables, I've just been sort of > assigned to the analysis of the task! > I know it'd be a million times easier with a different type of array but I > was wondering if it was at all possible without changing anything?
Yes, but storing your variables like that is going to bite you in the butt repeatedly in terms of code clarity and performance (since you're likely going to need to litter your code with EVAL statements) and distinguishing which variables are in the workspace to be summed and which are not could be error-prone. Suppose that you had a different 3-by-4 array named DoNOTAdd in your workspace -- writing a flexible and general procedure that can determine that you need to add A, B, C, D, E, etc. without adding DoNOTAdd could be tough.
If you _can't_ avoid this naming scheme, you can at least mitigate it a bit in your code. Don't LOAD the data into separate variables; LOAD it into fields of a struct array and use dynamic field names.
data = load(myMatFile); listOfFields = fieldnames(data); data.(listOfFields{1}) % Extract the contents of one of the variables from the MAT-file
-- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
|
|
|