How to save a column into separate variables
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fernando Pérez Lara
el 18 de Oct. de 2018
Comentada: Fernando Pérez Lara
el 18 de Oct. de 2018
Hi, I want to save a column of a matriz into five variables, here is my code:
A = [1 0 0 0 -3 0;
0 1 0 0 -1 0;
0 0 1 0 -1 0;
0 0 0 1 -3 0];
I want to have into a, b, c, d and e the fifth column. Something like this:
a = 3
b = 1
c = 1
d = 3
Thank you!
0 comentarios
Respuesta aceptada
madhan ravi
el 18 de Oct. de 2018
Editada: madhan ravi
el 18 de Oct. de 2018
A = [1 0 0 0 -3 0;
0 1 0 0 -1 0;
0 0 1 0 -1 0;
0 0 0 1 -3 0];
a=A(:,1)
b=A(:,2)
c=A(:,3)
d=A(:,4)
e=A(:,5)
4 comentarios
Stephen23
el 18 de Oct. de 2018
Editada: Stephen23
el 18 de Oct. de 2018
"I thought that I could put"
[a, b, c, d] = X(:, 5)
Nope. X is one variable, a, b, c, and d are four separate variables.
Z = num2cell(X(:,5));
[a,b,c,d] = Z{:}
But I would recommend just using indexing, exactly as madhan ravi's answer shows.
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!