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.

 Respuesta aceptada

Voss
Voss el 17 de Mayo de 2022
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 comentarios

woohyuck kang
woohyuck kang el 17 de Mayo de 2022
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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Versión

R2020b

Preguntada:

el 17 de Mayo de 2022

Comentada:

el 17 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by