Solution to equation into matrix form?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
John
el 15 de Oct. de 2014
Comentada: Star Strider
el 15 de Oct. de 2014
Here is my code:
x=linspace(1,5,5)'
For c=1:2
y=x+1*c
end
I want the solution to be stored in a 5x2 matrix:
2 3
3 4
4 5
5 6
6 7
Does anyone know how to do this?
0 comentarios
Respuesta aceptada
Star Strider
el 15 de Oct. de 2014
You need to subscript it, and it works:
x=linspace(1,5,5)'
for c=1:2
y(:,c)=x+1*c;
end
It produces the matrix you posted.
2 comentarios
Star Strider
el 15 de Oct. de 2014
My pleasure!
The ‘y(:,c)’ assignment forces the output to be rows rather than columns, resulting in the (5x2) size you want. Reversing the order of the subscripts to ‘y(c,:)’ results in a (2x5) matrix. The position of the counter variable in the subscript order determines how the results of the calculations are added to the array.
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!