Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
I am having trouble saving large vectors inside of a nested loop. Can anyone help out? Thanks!
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
dat = dlmread('thermal.dat');
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]
aa = dlmread([num2str(i),'/',num2str(j),'/out'],'',1,0);
bb = aa(:,6); %initialize pxx
end
end
0 comentarios
Respuestas (1)
KSSV
el 30 de Nov. de 2017
clearvars
dat = dlmread('thermal.dat');
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]
aa = dlmread([num2str(i),'/',num2str(j),'/out'],'',1,0);
bb = aa(:,6); %initialize pxx
iwant(j,i) = std(b) ; % get standard deviation and save
end
end
1 comentario
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!