How do I show my fprintf of for loop in textbox GUI

2 views (last 30 days)
Hi, I am trying to show my fprintf in my textbox in the GUI but cannot find the right solution
Basically this is an arithmetic progression, I am trying to create a GUI where students can enter the first term (a3), the common difference (d3) and the n value (n3) which how many terms they would like.
My code below shows a satisfying output in the command window, which shows the value n and the Term next to it, but I could not get the right code to make them appear in my textbox in the GUI (text30).
a3content=get(handles.a_2_edit,'String')
d3content=get(handles.d_3_edit,'String')
n3content=get(handles.n_3_edit,'String')
a3=str2num(a3content)
d3=str2num(d3content)
n3=str2num(n3content)
for k=1:n3
set(handles.text30,'String',fprintf('%.0f\t %.2f\n',k, a3+(k-1)*d3))
end
output:
1 3.00
2 6.00
3 9.00
4 12.00
  1 Comment
NUR SYAZANA YUSRI
NUR SYAZANA YUSRI on 29 Jul 2020
@Image Analyst I've using your guide for most my MATLAB project and they were so helpful, please help me with this one

Sign in to comment.

Accepted Answer

Rik
Rik on 29 Jul 2020
You should use sprintf to create a char array that you can display in your text box.
If you want to add lines instead of overwriting, append the created char, instead of replacing the contents of text30.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps 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!