mean of two matrix groups split by name
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Rik
el 3 de Jul. de 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.
Respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!