how can I give name to an array column?
조회 수: 65 (최근 30일)
이전 댓글 표시
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
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
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
2023년 1월 11일
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
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 Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!