how can I give name to an array column?
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I was given an excel file that I inserted to matlab using "readtable", now I need to convert the table to an array while keeping the column names in the matrix. when using "table2array" the column name disappear.
How can keep the column name in the array?
4 Kommentare
Adam Danz
am 11 Jan. 2023
What you're describing isn't possible in MATLAB. The only data type that contains header names is table and timetable.
John D'Errico
am 11 Jan. 2023
A double precision array CANNOT have elements that are strings, characters, etc. ANYTHING else but a double is out. So you cannot do what you ask to do, at least if the result would be a numeric array.
And you cannot "name" a column of an array. Although if you wanted, you could define variables named "ECG_Signal" and "t_sec_".
However, you can have a separate vector of column names, where you would store them in a cell array.
columnnames = {'ECG_Signal' , 't_sec_'};
You could even store everything in one struct, where you would convert the table into various fields of a struct.
struct.columnnames = {'ECG_Signal' , 't_sec_'};
struct.data = [an nx2 array]
Antworten (1)
the cyclist
am 11 Jan. 2023
Some of them, for example the "table" and "structure" data type, can have variable names associated with them. Others, such as the purely numeric arrays like the "double" data type, cannot.
You may have been asked to do the impossible. Was this a written assignment that you can share with us? Maybe you misunderstood the instructions.
3 Kommentare
Adam Danz
am 11 Jan. 2023
A matrix can only store numeric values.
Cell arrays can store mixed class such as a row of strings in the top row and numers in all other rows but this would be referred to as an array, specifically a cell array, but it would not be recommended in this case.
If this is the description from the assignment, it's poorly worded or misguided.
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!