mean of two matrix groups split by name
조회 수: 1 (최근 30일)
이전 댓글 표시
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
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 Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!