How do you automatically put values into an array when in a loop?
Show older comments
I currently have the for loop below. where NoS is the number of subjects and NoJ is the number of jumps.
NoS = 6
NoJ = 4
bars = NaN(NoS*NoJ,1);
errors = NaN(NoS*NoJ,1);
for i=1:NoS*NoJ
clear ave stdev
ave = mean(data((i*NoJ)-3:(i*NoJ),3));
stdev = std(data((i*NoJ)-3:(i*NoJ),3));
bars(i) = ave;
errors(i) = stdev;
end
At the moment this imports the means and standard deviations straight into the arrays bars and errors in one long column (a vector). I however want it so it will each subject data into a new row in the array. In this example that would mean the array would be a 6x4 as there are 6 subjects and 4 jump types for each subject. I need the first 4 values to go in spaces (1,1) (1,2) (1,3) and (1,4) and then for it to move down to the next row and import the next 4 values in the same fashion.
1 Comment
Dave
on 30 Apr 2013
Answers (1)
Iman Ansari
on 30 Apr 2013
Hi. Without loop:
NoS = 6;
NoJ = 4;
data1=reshape(data(1:96,3),4,24);
bars=mean(data1);
errors=std(data1);
bars=reshape(bars,4,6)';
errors=reshape(errors,4,6)';
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!