Using set for multiple objects in a loop
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2017-2-20
How would the sensors be constructed? For example have you constructed them as arduino i2c devices?
采纳的回答
更多回答(1 个)
Walter Roberson
2017-2-20
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!