필터 지우기
필터 지우기

Labeling the columns in an array

조회 수: 33 (최근 30일)
FW
FW 2019년 7월 12일
댓글: Peter Jarosi 2019년 7월 12일
If we import a .csv or Excel file using readtable, and then convert the table to an array as the following:
Data=table2array(readtable('Filename.csv'));
We get an output like the following. This syntax process removed all the original labels of each column. Is it possible to label the columns, such as Serial number, Time, Signal 1, Signal 2?
Although one can read and separately isolate the columns, does Matlab allow retaining the labels? Thanks
DATA.jpg
  댓글 수: 1
John Doe
John Doe 2019년 7월 12일
Unless you are doing an operation that does not support table data sets, leave your data as a table.
Alternatively, save all your variables to cell array using:
varNames = t.Properties.VariableNames;
Then when you want to output your data can recreate the table afterwards.
Don't split your data in to individual variables.

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

채택된 답변

Peter Jarosi
Peter Jarosi 2019년 7월 12일
편집: Peter Jarosi 2019년 7월 12일
Do not convert your table into an array! Just use table object!
Data=readtable('Filename.csv');
Later, if you want to refer it as a matrix you can use the following syntax:
Data{:,:}
If you want to refer your columns as column vectors use:
Data{:,{'Serial number'}}
Data{:,{'Time'}}
etc.
If you want your signals in a n by two matrix:
Data{:,{'Signal 1','Signal 2'}}
  댓글 수: 2
FW
FW 2019년 7월 12일
Thanks all, I want to apply moving average smoothing on column 3. Couple of other operations don't work in the table after smoothing. Currently, I read the columns from the array. May be it would be worthwhile to keep the table for reference and then use the array for operations.
% Hamming filter
L=13; % size of Hamming windows
H=hamming(L);
Signal1=Data(1:382, 3); data in column in 3
Signal1_Hamming = conv(Signal1, H./sum(H), 'same') ;
Peter Jarosi
Peter Jarosi 2019년 7월 12일
You're welcome!
You can still use your data in a table format, just change your 3rd line to:
Signal1=Data{1:382, {'Signal 1'}}; % data in column in 3

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by