How to save the variable from the workspace into csv or excel file

301 views (last 30 days)
I am using the code below to save one of the variable from the workspace into the
excel file but struggling to save it, what it is doing is saving some gibrish into excel rather then the data.
close all; clear all; clc;
folder = fullfile('D:','Velocity_Analysis','paraViewpractise');
files = dir( fullfile(folder, '*.csv') );
for ii = 1:length(files)
data = readmatrix(fullfile(files(ii).folder,files(ii).name), 'NumHeaderLines', 1)
res(:,ii)= data(:,3);

Accepted Answer

Ameer Hamza
Ameer Hamza on 2 Dec 2020
Edited: Ameer Hamza on 2 Dec 2020
save() is for saving in a .mat file. You need writematrix() for xls
writematrix(res, filename);
For releases older than R2019a, use xlswrite().
Ameer Hamza
Ameer Hamza on 2 Dec 2020
You may consider attaching your complete code including the line writematrix. Maybe it will give some hints of the issue.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by