Remove the variable column generated by the rows2vars function

25 views (last 30 days)
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?

Accepted Answer

Kritika Bansal
Kritika Bansal on 20 Aug 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:

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!