Appending variables to variable structure
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Jan
2012 年 4 月 11 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!