Using set for multiple objects in a loop
5 views (last 30 days)
Show older comments
Hi,
I am using guide and trying to update the string for 4 edit fields on my GUI. Here is some pseudo-code (not functional) that hopefully conveys my question:
handles.nSensors = 4;
for i = 1:handles.nSensors
readVal(handles.sensorValue(i)); % read value of sensor 'i'
set(handles.sensorLabel{i},'String',num2str(handles.sensorValue(i))); % update GUI text field 'i' with value of sensor 'i'
end
My issue is with the second line in the for loop; how can I rename the first argument each iteration? I'm not sure I understand what type of object the first argument is. Is it a function handle?
Thanks for the help, if this question is unclear please let me know and I will try to explain better.
1 Comment
Walter Roberson
on 20 Feb 2017
How would the sensors be constructed? For example have you constructed them as arduino i2c devices?
Accepted Answer
More Answers (1)
Walter Roberson
on 20 Feb 2017
There are some kinds of objects that you can construct vectors out of; for example you can have a vector of graphics objects.
However, some kinds of objects have attached meaning to () syntax that is something different than selection between multiple similar objects; you cannot create arrays of those objects. For example, function handles use () to indicate that function is to be invoked, so you cannot create a normal array of function handles.
If you happen to be using an object that you cannot create arrays of, then you will need to place the objects into cell arrays. You can, for example, have cell arrays of function handles.
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!