How do I change a string object into a variable name that heatmap accepts
2 次查看(过去 30 天)
显示 更早的评论
I have a string array of table variable names that i want to feed into heatmap. I use 'for' to loop through a table to generate heatmaps that go to power point.
heatmap(engine_config, group_perms(i,1), group_perms(i,2))
I get this error.
Error using heatmap
'XVariable' value does not refer to a valid variable in the source table.
Caused by:
Unrecognized table variable name 'group1'.
heatmap wants this, not string:
heatmap(engine_config, 'group_1', 'group_2')
This is probably a real simple solution. I have not nailed down the use of brackets/parenthases to get the right data type.
I have tried some matlab conversions but no luck.
Any help is appreciated.
group_perms 10x2 string
group1 group2
group1 group4
group1 group5
group1 group3
group2 group4
group2 group5
group2 group3
group4 group5
group4 group3
group5 group3
obtained using
group_perms = nchoosek(group_vars, 2);
group_vars is a string array of a subset of variable names in my large dataset. I use my string array throughout my program.
0 个评论
采纳的回答
Adam Danz
2023-1-4
编辑:Adam Danz
2023-1-4
If nchoosek returns a cell array of strings, you can index them using { }
try this.
heatmap(engine_config, group_perms{i,1}, group_perms{i,2})
or this to convert it to string array
group_perms = string(nchoosek(group_vars, 2));
heatmap(engine_config, group_perms(i,1), group_perms(i,2))
3 个评论
Adam Danz
2023-1-4
For my own sanity, could you show me exactly what this returns:
group_perms(i,1)
As well as this
engine_config.Properties.VariableNames
assuming this is your table.
更多回答(1 个)
Steven Lord
2023-1-4
This seems to work with a simpler example.
T = array2table(magic(5))
V = string(T.Properties.VariableNames)
heatmap(T, V(2), V(5)) % Using variables 2 and 5 as an example
Looking at your code, the example you posted that you said worked used "group_1" and "group_2" as variable names but the error message calls out that "group1" (no underscore) is not a variable in your table. What do your group_perms and group_vars variables contain: "group_1" or "group1"?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!