New user question on fprintf
1 view (last 30 days)
Show older comments
Christopher Hall
on 1 Feb 2015
Answered: Star Strider
on 1 Feb 2015
Hey, i'm a new user to Matlab and am working on some homework. I'm trying to figure out how to write a script that will prompt the user to input a character and then perform the following actions.
A. use fprintf to print the character without specifying a field width
B. use fprintf to print the character specifying a field width of 5
My code I've been working on is below, you can see my mistakes.
% Prompt user to enter character
disp ('Please enter a character...any character')
%STRvar = input('Please enter a character', 's')
%fprintf (' var1 is %3.1s/')
%character = input(' Enter a character: ', 's');
fprintf ('The character %d has no specified field width\n')
If anyone could help me it'd be appreciated, thanks!
0 Comments
Accepted Answer
Star Strider
on 1 Feb 2015
In this line:
fprintf ('The character %d has no specified field width\n')
you need to use the correct format descriptor to print a character (see the fprintf documentation for that), and you need to tell the fprintf function the character you want it to print. Other than that, you are where you want to be with it.
0 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!