Hi, I have three matrices A=[60x111], B=[60,11],C=[60,101];
here, N=60, a=111,b=11,c=101
for i=i:N
[Nd{:,i}] = ndgrid(1:a, 1:b, 1:c);
end
I want to use Nd{:,i} for each row of A,B,C. My output will be a 4 dim matrix (111x11x101x60) obtaind from final multiplication of
A(Nd{:i}).*B(Nd{:i}).*C(Nd{:i}). I dont know how to do that.
Thanks in advance.

댓글 수: 2

Guillaume
Guillaume 2019년 7월 31일
I'm not clear on what you're trying to do. Currently your loop just does the same calculation 60 times.
Can you provide a example of inputs and desired output, with smaller size matrices (e.g. N = 3, a = 2, b = 3, c = 4)?
kritika joshi
kritika joshi 2019년 7월 31일
For A=rand(3,2), B=rand(3,3),C=rand(3,4),D=rand(3,1), I actually want to multiply these matrices (A, B, C,D) using ndgrid. So that I will get a 4 dim matrix.

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

 채택된 답변

Guillaume
Guillaume 2019년 7월 31일

0 개 추천

It's not any clearer what you want, since you don't define what you mean by multiply and since ndgrid has nothing to do with multiplication.
Perhaps, you're looking for this:
result = A .* permute(B, [1, 3, 2]) .* permute(C, [1, 3, 4, 2])
which will give you 4D matrix of M x N x P x Q for A of size M x N, B of size M x P and C of size M x Q.

댓글 수: 3

kritika joshi
kritika joshi 2019년 8월 1일
Thank you so much for your answer. But I want to arrenge it in (NxPxQxM) order with multiplication of D also.
Walter Roberson
Walter Roberson 2019년 8월 1일
permute(result, [2 3 4 1])
kritika joshi
kritika joshi 2019년 8월 1일
Thanks a lot.

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

추가 답변 (0개)

카테고리

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

질문:

2019년 7월 31일

댓글:

2019년 8월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by