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

조회 수: 233 (최근 30일)
Hi,
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.
Code:
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);
end
filename='workspace_variable.xls';
save(filename,'res');
winopen('workspace_variable.xls');

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 12월 2일
편집: Ameer Hamza 2020년 12월 2일
save() is for saving in a .mat file. You need writematrix() for xls
filename='workspace_variable.xls';
writematrix(res, filename);
For releases older than R2019a, use xlswrite().
  댓글 수: 8
muhammad choudhry
muhammad choudhry 2020년 12월 2일
R2020a, yea should work, as all the FAQs answers same as yours and I have tried different ways, I ended up doing it manually. Thanks anyway! I bother you with something else if i stuck again. Thanks for your support!
Ameer Hamza
Ameer Hamza 2020년 12월 2일
You may consider attaching your complete code including the line writematrix. Maybe it will give some hints of the issue.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by