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
0 个评论
采纳的回答
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');
0 个评论
更多回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!