Sum of values stored in an array of handles
3 次查看(过去 30 天)
显示 更早的评论
I got the following callback function
function solveclick(bl) %bl is an array of handles to pushbuttons (created with uicontrol)
for i=2:10
rows(i)=sum(get(bl(i,:),'value'));
end
end
What I'm trying to do is add the values of the pushbuttons in a row and store the individual sums in a vector called rows.
0 个评论
采纳的回答
Image Analyst
2020-4-1
Are you SURE you set the Value property of the buttons when you created them? You'd need to have done that for your code, though I think it's unusual. Most people would set the UserData property, or just keep a separate array for whatever numbers you want to store. Are you using GUIDE or App Designer?
更多回答(1 个)
Geoff Hayes
2020-4-1
Juri - the only problem that might exist for you (it did for me when i tried this) was that
get(bl(i,:),'value')
returned a cell array of numeric values which, when trying to sum that array, I observed a Undefined function 'sum' for input arguments of type 'cell' error message. To get around this, you would need to convert to a matrix
rows(i)=sum(cell2mat(get(bl(i,:),'value')));
另请参阅
类别
在 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!