how can I give name to an array column?

조회 수: 65 (최근 30일)
daniel
daniel 2023년 1월 11일
댓글: Adam Danz 2023년 1월 11일
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
Adam Danz
Adam Danz 2023년 1월 11일
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 2023년 1월 11일
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]

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2023년 1월 11일
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
daniel
daniel 2023년 1월 11일
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 2023년 1월 11일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by