Appending variables to variable structure
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi Everyone,
I'm running into some trouble converting a set of dependent and independent loops into a function I can use to run over my entire dataset (one subject at a time).
I've created a function that takes the filename and group membership of each subject as inputs and I want to store the result of all the loops in one Results structure, to do so I use the following lines of code:
Results(1,1).Average(group,1) = OUTPUTA;
Results(1,1).Name = 'Average Output A';
Results(2,1).Average(group,1) = OUTPUTB;
Results(2,1).Name = 'Average Output B';
save('Results','Results');
Now the 'group' variable is one of the input and indicates group membership and thus the position of the results in resulting structure. This seems to work fine running, however, it overwrites my previous results every time I run the code. How do I run it such that when using:
function [Results] = Run_Analysis(filename, group)
%with group == 2
is doesn't overwrite the run of group == 1, but instead appends it to the existing Results.mat in the sense that the outcome for the next run is placed in the second row.
Cheers,
Richard
0 Kommentare
Antworten (2)
Jan
am 11 Apr. 2012
I'm not sure, how the resulting struct array should look like. In general it should work like this:
if exist('Results.mat', 'file')
Results = load('Results.mat');
else
Results(1, 1).Name = 'Average Output A';
Results(2, 1).Name = 'Average Output B';
end
Results(1, 1).Average(group,1) = OUTPUTA;
Results(2, 1).Average(group,1) = OUTPUTB;
save('Results','Results');
0 Kommentare
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!