Info
This question is closed. Reopen it to edit or answer.
how to add multidimensional arrays
2 views (last 30 days)
Show older comments
Hi all,
I have the following commands:
j=1:N
elem(j,1,1)=alfa(j).*E0(1,1).*sigma(j,1,1);
elem(j,1,2)=alfa(j).*E0(1,2).*sigma(j,1,2);
elem(j,2,1)=alfa(j).*E0(2,1).*sigma(j,2,1);
elem(j,2,2)=alfa(j).*E0(2,2).*sigma(j,2,2);
Is there a way to write them in one compact form rather than four lines? Thank you.
0 Comments
Answers (1)
the cyclist
on 4 Dec 2013
Edited: the cyclist
on 4 Dec 2013
I think this will do what you want.
elem(j,1:2,1:2) = alfa(j).*E0(1:2,1:2).*sigma(1:2,1:2);
If each of those dimensions only runs over 1:2, then this can be shortened to
elem(j,:,:) = alfa(j).*E0.*sigma(j,:,:);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!