Info

# I am having trouble saving large vectors inside of a nested loop. Can anyone help out? Thanks!

1 view (last 30 days)
Jonathan Salazar on 30 Nov 2017
Closed: MATLAB Answer Bot on 20 Aug 2021
I have a script that pulls data for strain values out of files. This code was given to me and I am having the hardest time trying to modify it. the j loop cycles over 30 samples of the same experiment so that we could calculate average. the i loop cycles over different materials being tested. the bb data is the data I am Interested in which is a 5000 by 1 vector. I simply need to calculate the standard deviation for each row of the 30 samples so that I have 5000 std's for each iteration of i and save it in a matrix (so that i have a 5000 by 56 matrix after code is completed). every time I try to create a new variable to create a matrix or even simply save the current std the variable is no where to be found and is not saved to the work space. Any help would be apreciated. thank you!
clearvars
temp = dat(:,1);
k = dat(:,2);
epsilon = dat(:,3);
for i = 1:56
files = dir(num2str(i));
nsample = numel(files(~strncmpi('.',{files.name},1)));
aa = []; cnt2 = 0;
for j = 1:nsample%for 7: [1 2 3 4 6:12 14:20]
bb = aa(:,6); %initialize pxx
end
end

KSSV on 30 Nov 2017
clearvars
temp = dat(:,1);
k = dat(:,2);
epsilon = dat(:,3);
iwant = zeros(nsample,56) ; % initialize
for i = 1:56
files = dir(num2str(i));
nsample = numel(files(~strncmpi('.',{files.name},1)));
aa = []; cnt2 = 0;
for j = 1:nsample%for 7: [1 2 3 4 6:12 14:20]
bb = aa(:,6); %initialize pxx
iwant(j,i) = std(b) ; % get standard deviation and save
end
end