필터 지우기
필터 지우기

Add header to my new extracted data from a table?

조회 수: 34 (최근 30일)
mahrukh jamil
mahrukh jamil 2016년 7월 15일
편집: Peter Perkins 2016년 8월 3일
Hello, I have a .csv file that contain odd characters (french accent characters). I read the file with readtable command. Now from the table i extracted only 4 columns and their values having dimension x1data[(1354x4 double)]. I now need to add header to this new table and save it. I form a cell array col [%dimenion(1x4 cell)]. It don´t happen to add it using ´join´,´vertcat´ or ´horzcat´. I tried to convert both the data and col into table but it still gives me error. Can anyone help me how can i add header to a new data extracted from the original file? here is my line of code:
data= readtable('my_file.csv');
x1data= [data{:,3}(:,1), data{:,4}(:,1), data{:,6}(:,1), data{:,9}(:,1)]; %select only the data of interest
col_header={'time in seconds','point duration','epoch size','stage'}; %header for the x1data
col=cell2table(col_header); % (1x4 table)
mydata=array2table(x1data); % (1354x4 table)
Tnew=[mydata;col];
save the new table in new data
%csvwrite('16033NP3_ExtraitEvts.csv',col_header); %Write data and headers
Thank you
  댓글 수: 1
mahrukh jamil
mahrukh jamil 2016년 7월 15일
편집: Walter Roberson 2016년 7월 15일
Dear all thank you for viewing my question. I found out the solution. I just had to write my new data with array2table command with variable name. Just for reference that's what i did.
data= readtable('my_file.csv');
%select only the data of interest
x1data= [data{:,3}(:,1), data{:,4}(:,1), data{:,6}(:,1), data{:,9}(:,1)];
% new data table
mydata=array2table(x1data, 'VariableNames',{'time_in_seconds','point_duration','epoch_size','stage'});

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

채택된 답변

Peter Perkins
Peter Perkins 2016년 8월 3일
편집: Peter Perkins 2016년 8월 3일
mahrukh, there are much simpler ways to do this, especially your use of subscripting. For example:
data = readtable('my_file.csv');
mydata = data(:,[3 4 6 9]);
myData.Properties.VariableNames = {'time_in_seconds','point_duration','epoch_size','stage'};

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by