How to get the current variable value in Matlab GUI?

Hello Everyone, I have a GUI which starts plotting a variable value when I push start button and also displays the value of the same variable in Static Text box. The problem is that the variable value gets append in the text box, it does not clear the previous value before showing the current value. I want it to show only the current value of the variable in the box. I have attached the code and image of output for the reference. Thank you

 Accepted Answer

Adam
Adam on 3 Jun 2016
Edited: Adam on 3 Jun 2016
From what I can see at a quick glance, your handles.c is growing in the loop (i.e. it is a vector of values) and therefore so is your 'sum' variable and likewise your handles.avg therefore you would want to use
set(handles.value1,'String',handles.avg(end));
if this is your intended behaviour.
Aside from that:
  • never name a variable 'sum' or indeed any other name which will overwrite (or hide, rather) a function of the same name.
  • I'm not sure what your intention is with your 'clear handles.value1' statement, but even if it does no harm I doubt it is what you really want to do.
  • Are you intending to make use of all the things you are attaching to handles later on? If not then e.g. handles.c is un-necessary if it is only used within a single function.

1 Comment

Yes thank you very much. The problem is solved. * yes i will keep that in mind * with 'clear handles.value1' I was trying to clear the text box before it shows the next value *Yes I need the variable further in code with all the values.
Thank you once again.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!