How to create a row from x(1) to x(n)?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alex M
el 12 de Nov. de 2020
Respondida: Image Analyst
el 12 de Nov. de 2020
Hello
I am quite new to coding and trying to create a row where each term in the row is x followed by the column number in brackets. So [x(1) x(2) x(3) ... x(n)]
Many thanks
0 comentarios
Respuesta aceptada
Cris LaPierre
el 12 de Nov. de 2020
You might also just be needing to transpose you column vector to turn it into a row vector. Use ' for that. This is covered in 4.2.6.
x=[1:5]'
x1=x'
3 comentarios
Cris LaPierre
el 12 de Nov. de 2020
Ok, that is pretty simple as well, but not covered in Onramp.
x1 = "X(" + string(1:5) + ")"
Más respuestas (1)
Image Analyst
el 12 de Nov. de 2020
Try this:
n = 5;
for k = 1 : n
str(k) = string(sprintf('x(%d)', k));
end
str % Display in command window
You'll see:
str =
1×5 string array
"x(1)" "x(2)" "x(3)" "x(4)" "x(5)"
0 comentarios
Ver también
Categorías
Más información sobre String en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!