My reversed vector is outputting on five different lines in the command window. How can I output to just one line?

1 view (last 30 days)
Part of the assignment that I'm having trouble on calls for me to write a program that wants when a user inputs a 5 digit positive integer, the output would be the digits reversed.
Earlier in my assignment, it called for me to write a function when the user inputs a five digit positive integer, the output would be the five digits of that number. For example, five_digits(12345) = [1,2,3,4,5]. I completed this part with the code:
function N=five_digits(n)
N = (num2str(n))-'0';
end
In the workspace window, the N comes out to be [1,2,3,4,5].
So the part I'm having trouble on is the reversing of the digits and what the output is from the program I wrote. Here is the program I wrote for reversing of the digits using the five_digits function:
N = input('Input a five digit positive integer.\n');
C = fliplr(five_digits(N));
fprintf('%d\n', C);
When I run the program, if I enter 12345, my output would be 5 4 3 2 1, but each digit on five separate lines. However, in the workspace window, it does show that the digits were indeed reversed with [5,4,3,2,1].
What can I do to have the reversed vector output all on the same line just like how when I run the five_digits function when the digits are all spread out on one line?

Accepted Answer

Tom
Tom on 12 Sep 2012
The '\n' is creating a new line each time there is a digit:
fprintf('%d%d%d%d%d\n', C)
should work.

More Answers (1)

Daniel
Daniel on 12 Sep 2012
It did work thank you.

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!