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

조회 수: 3 (최근 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.

추가 답변 (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