How to change output from column to row?

19 次查看(过去 30 天)
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

采纳的回答

Arthur Roué
Arthur Roué 2020-7-17
编辑:Arthur Roué 2020-7-17
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');

更多回答(1 个)

Sydney Lang
Sydney Lang 2020-7-17
编辑:Sydney Lang 2020-7-17
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

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by