" Array dimensions must match for binary array op."

Dear experts,
I need your help;)
I got an Error :" Array dimensions must match for binary array op."
I have 1x14 cell ThAll : { 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double 4-D double}.
Each "4-D double" is a different size matrix . I need to find mean value matrix across all of these 4-D double matrices.
At first , I wanted to make all matrices in one ThAll cell array in the same size with NaN, then add all of them and find one mean value matrix across all matrices. I do it in next way:
for k = 1:length(ThAll) % Im not sure if Im making the same size for all matrices right; I think in this part is error
m = size(ThAll{k},1);
ThAll{k}(m+1, : , :, :) = NaN;
end
sum = ThAll{1}; % sum of all matrices
for i = 2:length(ThAll)
sum = sum + ThAll{i};
end
meanThAll = sum ./ length(ThAll); % one mean matrix across all matrices in cell array
Can someone help with this Error :" Array dimensions must match for binary array op" in my case ?
A lot thanks in advance!

댓글 수: 2

Which MATLAB release are you using? In particular, are you using R2016b or later?
IM
IM 2020년 6월 5일
Im using R2020a

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

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020년 6월 5일

0 개 추천

Here is one of the easy solutions:
for jj=1:numel(ThAll)
TH_all=ThAll{jj};
for kk=1:4
TH_ALL(jj, kk)=mean2(TH_all(:,:,kk));
end
end

댓글 수: 4

IM
IM 2020년 6월 6일
Hey Sulaymon! Thanks so uch for your answer! Anfortunally it dosnt work with my code.
In this way I got new Error : "Brace indexing is not supported for variables of this type". Idont know how to fix it...
is the error occurring on
TH_all=ThAll{jj};
if so could you confirm that ThAll is still your 1x14 cell array?
IM
IM 2020년 6월 6일
Hey Walter! Yes, the error "Brace indexing is not supported for variables of this type" occurring on TH_all=ThAll{jj};
After :
for jj=1:numel(ThAll)
TH_all=ThAll{jj};
for kk=1:4
TH_ALL(jj, kk)=mean2(TH_all(:,:,kk));
end
end
ThAll is no more 1x14 cell array . ThAll became simply "4-D double".
That does not make sense unless it happened before the code you posted.

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

질문:

IM
2020년 6월 5일

댓글:

2020년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by