uitable ColumnName from string array which keeps changing
Show older comments
I have a string array (a global variable) that's changing throughout the script. One iteration would be:
critMaterial = [ "Steel" "Stainless" "Titanium" "Aluminum" "Bronze" "Brass" "Copper" "Lead" ];
I also have a function that is plotting a bunch of uitables together with some subplots based on various criteria. uitable column names should match critMaterials strings, analogue to:
uitable(fig,'Data',data,...
'ColumnName',{"Steel" "Stainless" "Titanium" "Aluminum" "Bronze" "Brass" "Copper" "Lead" },...
'RowName',{'X [unit]';'Y [unit]'});
Now this being a function I need to automate how ColumnName is populated. Quick and crass way I came up with is:
uitable(fig,'Data',data,...
'ColumnName',{ critMaterial(1), critMaterial(2), etc., critMaterial(7)},...
'RowName',{'X [unit]';'Y [unit]'});
Apart from being cumbersome I also need to monitor what is the maximum number of cells in critMaterial and match that number.
Is there a more elegant way of doing this? How can I loop through critMateral from 1 to numel(critMaterial) and assign the column names in each iteration automatically?
While searching for the solution, I found this answer. However, that topic discusses pre-set VariableNames which I do not have.
Thanks.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB 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!