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
댓글 수: 0
답변 (1개)
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
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!