Remove the variable column generated by the rows2vars function

조회 수: 23 (최근 30일)
Joel Affolter
Joel Affolter 2019년 8월 16일
답변: Kritika Bansal 2019년 8월 20일
I am currently writing a script which imports data from an Excel file and stores the multiple arguments in a structure. Using the input arguments, some calculations are done and the imported results are added to the structure. The goal is to export the data as a excel file, which has the same name as the input file + 'Results' in front of it.
I've done so by converting the structure into a table and then writing an new excel file with abovehand mentionned 'Results' extension. However, I like it far more if the data is exported vertically and not horizontally, which is why I used the
rows2vars
function. The problem is that a "variable column" is generated in the beginning. I would like to remove this column if possible. Does anybody know a way to work around this?
  댓글 수: 1
dpb
dpb 2019년 8월 16일
t.OriginalVariableNames=[];
writetable(t,...)
or
writetable(t(:,2:end),...)

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

채택된 답변

Kritika Bansal
Kritika Bansal 2019년 8월 20일
Hi, 
Assuming you are MATLAB R2018a or later versions, you can use writetable function once you convert your structure to table. Following is the code to write your structure to an excel file without the first column: 
%dummy structure
S.Name = {'CLARK';'BROWN';'MARTIN'};
S.Gender = {'M';'F';'M'};
S.SystolicBP = [124;122;130];
S.DiastolicBP = [93;80;92];
T = struct2table(S); %convert structure to table
V = rows2vars(T);
V = V(:,2:end);
writetable(V, 'test.xls');
You can find the documentation of the functions used in above code in the following links:

추가 답변 (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