Filter löschen
Filter löschen

How do I multiply multidimensional array by a vector?

1 Ansicht (letzte 30 Tage)
Rahul Pillai
Rahul Pillai am 30 Aug. 2017
Bearbeitet: James Tursa am 30 Aug. 2017
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.

Antworten (1)

James Tursa
James Tursa am 30 Aug. 2017
Bearbeitet: James Tursa am 30 Aug. 2017
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.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by