필터 지우기
필터 지우기

How do I multiply multidimensional array by a vector?

조회 수: 1 (최근 30일)
Rahul Pillai
Rahul Pillai 2017년 8월 30일
편집: James Tursa 2017년 8월 30일
strainGP = zeros(S_num_elems, 4, 3, 1);
stressGP = zeros(S_num_elems, 4, 3, 1);
d_e=zeros(8,1);
for i=1:nodes
for m=1:4
strainGP(i,m,:,:)=H_all_elems(i,m,:,:)*d_e;
stressGP(i,m,:,:)=D(:,:)*strainGP(i,m,:,:);
end
end
I get error : Error using * Inputs must be 2-D, or at least one input must be scalar. To compute elementwise TIMES, use TIMES (.*) instead.

답변 (1개)

James Tursa
James Tursa 2017년 8월 30일
편집: James Tursa 2017년 8월 30일
First, whenever you are working with multi-dimensional matrices and need to access 2D slices of them for matrix manipulation, it is MUCH better to have those 2D slices as the first two dimensions of your array, not the last two dimensions. That way when you take the 2D slices they end up being MxN matrices instead of something like 1x1xMxN arrays. You could use the squeeze function to get things in the first two dimensions, but why complicate the code this way? Just rearrange your data so the slices are in the first two dimensions.
My advice is to change strainGP, stressGP, and H_all_elems to have those 2D slices as the first two dimensions in the array. Then your natural way of programming in the loops will work. Also, there are submissions in the FEX that will do multi-dimensional matrix multiplication on those 2D slices if they are arranged that way.

카테고리

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