I found out that the reason the real variable names was not shown in the table, was because the arrays I wanted to merge was in a struct array.
Merge arrays into table and keep the variable names
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Espen Mikkelsen
am 14 Mär. 2018
Bearbeitet: Peter Perkins
am 15 Mär. 2018
How can I merge arrays into a table and keep the variable names from the arrays=. I have tried to merge arrays into table like this:
table(array1,array2,array3);
In the new table the variable names is shown as var1,var2 and var3. I want the variable names to be shown as array1, array2 and array3. How can I do this?
2 Kommentare
Akzeptierte Antwort
Birdman
am 14 Mär. 2018
table function has VariableNames option, which can be used as follows:
array1=[1;2];
array2=[3;4];
array3=[5;6];
table(array1,array2,array3,'VariableNames',{'array1','array2','array3'})
1 Kommentar
Peter Perkins
am 15 Mär. 2018
Bearbeitet: Peter Perkins
am 15 Mär. 2018
You do not need this, though. In that code, the table's variable names will automatically be "array1", etc. So the original post is not telling us something important.
If the actual line of code were, for example
table(array1(1:10),array2(1:10),array3(1:10))
then you would have to specify variable names. But if it's really
table(array1,array2,array3)
then it happens automatically.
Edit: OK, also if the line is table(s.array1,s.array2,sarray3), then you would have to specify names. But as Stephen says, you should use struct2table for that.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables 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!