Change the value of a variable generated by app designer
Show older comments
Hi,
I use the matlab app designer that creates, in this instance, mutiple numerical edit boxes. In my case this are 30 edit boxes so I wanted to use a for-loop so to not hardcode. All the edit boxes have variable names like editBox_1. I tried to change the value of the edit box with:
for i = 1:30
eval(['editBox_' i '.Value']) = i*50; %in my case the value of editBox_i needed to be i*50
end
This did not change the value of the edit box. Can anyone help me out?
editBox_1.Value = 50 does change the value btw
Accepted Answer
More Answers (1)
Allen
on 24 May 2022
Tim,
Without reassigning the edit boxes to a seperate variable, editBox_# in this case, you can use something similar to update values for multiple edit boxes. Note that for this method to work you need to have the main variable constant and be able to edit the property or structure field names. My example uses app as the primary variable.
for i=1:30
app.("editBox_"+i).Value = i*50;
end
2 Comments
Tim Reddering
on 30 May 2022
Allen
on 31 May 2022
Glad to be of help. Please be sure to accept the answer so that others may also find this post helpful.
Categories
Find more on Data Type Identification in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!