Need help with looping data files in
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Kevin Holly
on 20 Jan 2022
Edited: Kevin Holly
on 20 Jan 2022
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 Comments
Kevin Holly
on 20 Jan 2022
Alternatively, you could write the index as such:
idx = [0,10,20,50,100,110,120,150]
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!