Suppose I have some matrices, A,B,C to Z.
A = [ 1 2 3 4; 1 2 3 4]
B = [ 1 2 1 2; 3 2 1 2]
....
Z = [1 3 1 3; 2 3 2 3]
Like vectors, how can I create variables that store these arrays in order?
ex) v=[ 1;2;3;4;5;6;1;2;3;4;5;] v(2)=2
What I want is
Array (2) = B = [1212; 3212] appears.

 Réponse acceptée

You can use a cell array:
Array = { ...
[ 1 2 3 4; 1 2 3 4] ...
[ 1 2 1 2; 3 2 1 2] ...
[ 1 3 1 3; 2 3 2 3] ...
};
Array{1}
ans = 2×4
1 2 3 4 1 2 3 4
Array{2}
ans = 2×4
1 2 1 2 3 2 1 2
Array{3}
ans = 2×4
1 3 1 3 2 3 2 3
v = {[1;2;3;4;5;6;1;2;3;4;5;] 2};
v{1}
ans = 11×1
1 2 3 4 5 6 1 2 3 4
v{2}
ans = 2
Array and v are each cell arrays.

2 commentaires

A = [zerov(t) onev(t); zerov(t) (-(B(t)/J(t))+(p*Kt(t)*lambda_m(t))/(J(t)*Rs(t)))]
I want the array to have A(1) and A(2) store a matrix of vector variables as t increases by 1.
You can use curly braces { } to construct a cell array. For example:
t = 0:10;
A = { ...
[zeros(size(t)); ones(size(t))] ...
t.^2+2*t-4 ...
}
A = 1×2 cell array
{2×11 double} {[-4 -1 4 11 20 31 44 59 76 95 116]}
A{1}
ans = 2×11
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
A{2}
ans = 1×11
-4 -1 4 11 20 31 44 59 76 95 116

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by