Need help with looping data files in

5 vues (au cours des 30 derniers jours)
David Morris
David Morris le 20 Jan 2022
Modifié(e) : David Morris le 20 Jan 2022
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.

Réponses (1)

Kevin Holly
Kevin Holly le 20 Jan 2022
Modifié(e) : Kevin Holly le 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 commentaires
Kevin Holly
Kevin Holly le 20 Jan 2022
Alternatively, you could write the index as such:
idx = [0,10,20,50,100,110,120,150]
David Morris
David Morris le 20 Jan 2022
Modifié(e) : David Morris le 20 Jan 2022
Hi, so I just figured it out. I changed it to this
clc;
clear;
close all;
HeaderRowCount = 7;
trials = 3;
i = 0;
for idx = [0,10,20,50,100,110,120,150]
i = i + 1;
for R = 1:trials
A = importdata(['Static_' num2str(idx) '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
I'm getting an 8x3 maxtrix which is great, thanks for the help.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Scripts dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by