Appending variables to variable structure
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Jan
le 11 Avr 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 commentaires
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!