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

3 vues (au cours des 30 derniers jours)
NUR SYAZANA YUSRI
NUR SYAZANA YUSRI le 29 Juil 2020
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 commentaire
NUR SYAZANA YUSRI
NUR SYAZANA YUSRI le 29 Juil 2020
@Image Analyst I've using your guide for most my MATLAB project and they were so helpful, please help me with this one

Connectez-vous pour commenter.

Réponse acceptée

Rik
Rik le 29 Juil 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.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by