how can I give name to an array column?

18 Ansichten (letzte 30 Tage)
daniel
daniel am 11 Jan. 2023
Kommentiert: Adam Danz am 11 Jan. 2023
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
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
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]

Melden Sie sich an, um zu kommentieren.

Antworten (1)

the cyclist
the cyclist am 11 Jan. 2023
MATLAB has several data types.
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
daniel
daniel am 11 Jan. 2023
the assignment says: Using a built-in Matlab command (do not use IMPORT). In this exercise (you must take in the table and arrange in a matrix including the titles
Adam Danz
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by