Define a series of matrices

9 views (last 30 days)
Mou Ab
Mou Ab on 21 Mar 2020
Commented: Walter Roberson on 21 Mar 2020
How do I define the next series of matrices
A=[0,1;sigma,0].
where
sigma=[-5:0.01:-4]
And I want the label to be as follows
A1=[0,1;sigma(1),0]

Accepted Answer

Stephen23
Stephen23 on 21 Mar 2020
Edited: Stephen23 on 21 Mar 2020
Using numbered variables is not going to be neat or efficient. The MATLAB approach would be to use one array, e.g.:
sigma = -5:0.01:-4; % the square brackets are superfluous
N = numel(sigma);
A = [zeros(N,1),ones(N,1),sigma(:),zeros(N,1)]
Each row of A is one of your output vectors, e.g.:
A(1,:)
  2 Comments
Mou Ab
Mou Ab on 21 Mar 2020
but we get a vector not a matrix
Walter Roberson
Walter Roberson on 21 Mar 2020
sigma = -5:0.01:-4; % the square brackets are superfluous
N = numel(sigma);
A = [zeros(1,1,N),ones(1,1,N); reshape(sigma,1,1,N), zeros(1,1,N)];
A is now a 2 x 2 x 101 array. A(:,:,37) would correspond to what you were hoping to see as a separate variable A37

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!