Need help with looping data files in
이전 댓글 표시
Hi, I've been working on writing this script that's supposed to read in 24 files, in sets of 3 as there are 3 trials being ran for different weight amounts. My issue is that it's only keeping the last 3 files worth of data while overwritting the rest. I know its due to how I set up my for loops I'm just unsure of how to fix it, as I've been looking around and trying different things without any luck.
HeaderRowCount = 7;
trials = 3;
for idx = setdiff(0:10:150,[30:10:40 60:10:90 130:10:140])
for R = 1:trials
A = importdata(['Static_' num2str(idx) 'g_5in_T' num2str(R) '.txt'], '\t', HeaderRowCount);
Strain{R} = A.data(1:end-1,2);
M(R) = mean(A.data(1:end-2,2));
end
end
Here's my code for reference. The reason I have that array in the setdiff is due to my weights being 0,10,20,50,100,110,120,150. Any help would be great, thanks.
답변 (1개)
Kevin Holly
2022년 1월 20일
편집: Kevin Holly
2022년 1월 20일
HeaderRowCount = 7;
trials = 3;
idx = setdiff(0:10:150,[30:10:40 60:10:90 130:10:140]);
for i = 1:length(idx)
for R = 1:trials
A = importdata(['Static_' num2str(idx(i)) 'g_5in_T' num2str(R) '.txt'], '\t', HeaderRowCount);
Strain{i,R} = A.data(1:end-1,2);
M(i,R) = mean(A.data(1:end-2,2));
end
end
댓글 수: 2
Kevin Holly
2022년 1월 20일
Alternatively, you could write the index as such:
idx = [0,10,20,50,100,110,120,150]
David Morris
2022년 1월 20일
편집: David Morris
2022년 1월 20일
카테고리
도움말 센터 및 File Exchange에서 Scripts에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!