Creating Multiple Arrays within a For Loop

3 views (last 30 days)
I'm wondering if there is a way the create multiple new arrays within a for loop.
I have the following equation that I'm trying to use.
The right hand side 3x1s are constant, but there are multiple values of z which then change 3x1 value on the left hand side.
Is there way that I could have z1 give LHS array 1, z2 give LHS array 2 and so within a for loop?

Accepted Answer

Matt J
Matt J on 25 Apr 2020
Edited: Matt J on 25 Apr 2020
You wouldn't do that with a loop. You would just use vector arithemtic,
eps0=rand(3,1); %fake RHS data
kappa=rand(3,1);
z=rand(1,20);
eps=eps0+kappa*z;
epsxx=eps(1,:);
epsyy=eps(2,:);
gammaxy=eps(3,:);
  3 Comments
Matt J
Matt J on 25 Apr 2020
Let's rename things a bit,
strain=eps0+kappa*z; %formerly eps=eps0+kapp*z
Here, strain will be a 3xN matrix whose columns are each of the N strains. So you have all of your results in that one matrix.
Rémi Durocher
Rémi Durocher on 25 Apr 2020
That makes a lot more sense. Thanks for your help!

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!