sprintf/fprintf help
Ältere Kommentare anzeigen
n=10 if i want the output to say "You have done this activity 10 times" how would i write it? I know for fprintf('You have done this activity \n'), the n would go in there, but is there a write is so that i could include words after \n? And should i use sprintf or fprintf?
Akzeptierte Antwort
Weitere Antworten (1)
Rik
am 30 Mai 2017
You should have a look at the documentation. Just type doc sprintf and it will open.
fprintf writes (prints) a formatted string to a file (the command output counts as a file in this case), sprintf writes a formatted string. That means that the second can be used to create a variable. In your case you need to use this:
fprintf('You have done this activity %d times \n',n)
The %d means that the first extra input should be converted to a digit, the \n is simply a new line indicator. For a full list of the possibilities and other special characters, just have a look at the documentation. That solves most of the problems (a second option is to [insert favorite search engine] an example)
Kategorien
Mehr zu Text Analytics Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!