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

2 ビュー (過去 30 日間)
NUR SYAZANA YUSRI
NUR SYAZANA YUSRI 2020 年 7 月 29 日
編集済み: NUR SYAZANA YUSRI 2020 年 7 月 29 日
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.
  1 件のコメント
NUR SYAZANA YUSRI
NUR SYAZANA YUSRI 2020 年 7 月 29 日
thank you, let me work on that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by