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!