Sum of values stored in an array of handles
3 views (last 30 days)
Show older comments
Juri Augsburger
on 1 Apr 2020
Commented: Juri Augsburger
on 2 Apr 2020
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 Comments
Accepted Answer
Image Analyst
on 1 Apr 2020
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?
More Answers (1)
Geoff Hayes
on 1 Apr 2020
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')));
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!