How do I change a string object into a variable name that heatmap accepts
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Adam Danz
am 4 Jan. 2023
Bearbeitet: Adam Danz
am 4 Jan. 2023
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 Kommentare
Adam Danz
am 4 Jan. 2023
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.
Weitere Antworten (1)
Steven Lord
am 4 Jan. 2023
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"?
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!