mean of two matrix groups split by name

1 Ansicht (letzte 30 Tage)
Nik Rocky
Nik Rocky am 3 Jul. 2020
Kommentiert: Rik am 3 Jul. 2020
Hello,
I have two groups of similar measures. Every file .mat with matrix M will be loaded from in loop and I want to make a mean of both groups separately (number of measures are symmetric)
"M4_Distance_0.5m_SONY_PCM_D50_F1_MS1" and "M4_Distance_2m_SONY_PCM_D50_F1_MS1":
013_M4_Distance_0.5m_SONY_PCM_D50_F1_MS1.mat
014_M4_Distance_0.5m_SONY_PCM_D50_F1_MS1.mat
015_M4_Distance_0.5m_SONY_PCM_D50_F1_MS1.mat
016_M4_Distance_0.5m_SONY_PCM_D50_F1_MS1.mat
017_M4_Distance_0.5m_SONY_PCM_D50_F1_MS1.mat
013_M4_Distance_2m_SONY_PCM_D50_F1_MS1.mat
014_M4_Distance_2m_SONY_PCM_D50_F1_MS1.mat
015_M4_Distance_2m_SONY_PCM_D50_F1_MS1.mat
016_M4_Distance_2m_SONY_PCM_D50_F1_MS1.mat
017_M4_Distance_2m_SONY_PCM_D50_F1_MS1.mat
I see a way to make it by count (if number of all *.mat files in folder are 10, so there are 2 groups with 5 files)
Or by name:
cnt1 = 0;
cnt2 = 0;
Res1 = zeros();
Res2 = zeros();
for .....
str = strsplit(name, '_')
str = str{1,end-5}
if strcmp(str,'0.5m')
Res1 = Res1 + M;
cnt1 = cnt1 + 1;
elseif strcmp(str,'2m')
Res2 = Res2 + M;
cnt2 = cnt2 + 1; % I know, one cnt is enough
end
end
mean1 = (Res1/cnt1)
mean2 = (Res2/cnt2)
Or maybe there are a better way to solve it? (There are sometimes up to 100 matrix) Thanks!
  3 Kommentare
Nik Rocky
Nik Rocky am 3 Jul. 2020
Hello, yes it is! The whole Problem is with labels. There are actually more than two groups. So for every case one if condition is not the nicest way. Moreover - I need a legend and plot all values in one graph.
Rik
Rik am 3 Jul. 2020
Then an array makes even more sense. You shouldn't be using an endless stream of if statements, you should be using ismember instead. Before your loop, generate the list of cases, then loop through the files. I may write up an example later.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by