Remove the variable column generated by the rows2vars function

23 vues (au cours des 30 derniers jours)
Joel Affolter
Joel Affolter le 16 Août 2019
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 commentaire
dpb
dpb le 16 Août 2019
t.OriginalVariableNames=[];
writetable(t,...)
or
writetable(t(:,2:end),...)

Connectez-vous pour commenter.

Réponse acceptée

Kritika Bansal
Kritika Bansal le 20 Août 2019
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:

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by