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

3 次查看(过去 30 天)
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 个评论
NUR SYAZANA YUSRI
NUR SYAZANA YUSRI 2020-7-29
@Image Analyst I've using your guide for most my MATLAB project and they were so helpful, please help me with this one

请先登录,再进行评论。

采纳的回答

Rik
Rik 2020-7-29
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by