Info

This question is closed. Reopen it to edit or answer.

how to add multidimensional arrays

2 views (last 30 days)
Likun
Likun on 3 Dec 2013
Closed: MATLAB Answer Bot on 20 Aug 2021
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.

Answers (1)

the cyclist
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,:,:);

Community Treasure Hunt

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

Start Hunting!