mean of two matrix groups split by name

조회 수: 1 (최근 30일)
Nik Rocky
Nik Rocky 2020년 7월 3일
댓글: Rik 2020년 7월 3일
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
Nik Rocky
Nik Rocky 2020년 7월 3일
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 2020년 7월 3일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by