How to change output from column to row?

20 visualizaciones (últimos 30 días)
Mark Ian
Mark Ian el 17 de Jul. de 2020
Editada: Sydney Lang el 17 de Jul. de 2020
a = input('Enter first number:');
b = input('Enter second number:');
for A=a:b
reshape(A,1,[]);
fprintf('%d \n', A)
end
this is my code but I cant change the answer to horizontal orientation
The output goes like this
Enter first number:1
Enter second number:3
1
2
3

Respuesta aceptada

Arthur Roué
Arthur Roué el 17 de Jul. de 2020
Editada: Arthur Roué el 17 de Jul. de 2020
You are printing in a loop with a line return at each step. This works :
a = input('Enter first number:');
b = input('Enter second number:');
fprintf('%d ', a:b);
fprintf('\n');

Más respuestas (1)

Sydney Lang
Sydney Lang el 17 de Jul. de 2020
Editada: Sydney Lang el 17 de Jul. de 2020
I'm not quite sure what you're doing with the reshape.
Use the .' notation to transpose a matrix
x = 1
2
3
x = x.';
x = 1 2 3

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by