MATLAB Answers

how to insert fprintf value into GUI edit text box?

15 views (last 30 days)
Phoebe
Phoebe on 18 Apr 2021
Commented: Phoebe on 23 Apr 2021
Hi there! I'm having issues on inserting my fprintf value into the GUI's edit text box...I think the error is at where I marked below but I can't seem to solve it. If you try to remove those two lines of code and just leave there as "fprintf('%s', morse{index});" , you will see my desire output at the command window...
In this case, you will see something similar as mentioned above but the difference is there'll be a random number showing in the GUI's edit text box...can someone help ? thanks!
morseoutput=fprintf('%s', morse{index}); %(I think here's the error)
set(handles.morsecode_output,'string',morseoutput) ;
  1 Comment
Stephen Cobeldick
Stephen Cobeldick on 19 Apr 2021
"...there'll be a random number showing in the GUI's edit text box"
Not random: the fprintf documentation states that it returns the number of bytes printed to the command window or file.

Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 18 Apr 2021
Edited: Stephen Cobeldick on 18 Apr 2021
You need to use sprintf, not fprintf:
  • sprintf creates a character vector/string (this is what you need).
  • fprintf prints directly to a file or the command window.
  24 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!