Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
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

답변 (1개)

KSSV
KSSV 2017년 11월 30일
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
Jonathan Salazar
Jonathan Salazar 2017년 11월 30일
Thank you for the quick reply! this gives me a 56 by 2 matrix. I need to save all 5000 std's for each iteration of i. I believe i need to first save a 5000 by 30 vecter of bb then take the row-wise std to obtain a 5000 by 1 vector. I then want to place this in the ith column. Is there any way to do this? thanks!

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by