How to save output of variable in csv file?
古いコメントを表示
I have MATLAB code and output is saved in variable and i want to save in csv file. And there is no example of that in doc of MATLAB. I have attached the code and variable name is"TY".
採用された回答
その他の回答 (2 件)
Md. Al-Imran Abir
2022 年 7 月 4 日
3 投票
At present, csvwrite (documentation) is not recommended. If one has a newer version of MATLAB (2019a or later), writematrix (documentation) is the preferred way.
4 件のコメント
Star Strider
2019 年 4 月 26 日
I would write it as I showed you in: Transpose/combine several variables using csvwrite or writematrix.
hameed asmath
2020 年 11 月 7 日
hello joh and strider!
Iam facing the same problem. did u solved this problem?. Kindly share the any sample code for the solution.
Thank you
Shekhar Vats
2021 年 4 月 28 日
This is a stupid bruteforce method, if you find a better one please share. I have seen people just pointing to the default matlab way where you can save one variable. What if you have 1000's of variable that will take all the time. I hope someone will share a better code
Please use the following link: https://www.mathworks.com/matlabcentral/fileexchange/28343-column-converter-for-excel
for downloading xlscol function
clear all; close all; clc;
current_dir = pwd;
[Filename, Pathname] = uigetfile('Select File'); % select file
file_to_be_loaded = [Pathname '\' Filename]; % get file path and name
load(file_to_be_loaded); % load file
Filename
clear Pathname file_to_be_loaded current_dir
vars=who;
sheet = 1;
for n=1:size(vars)
n
xlRange = [xlscol(n) '1'];
xl_range = [xlscol(n) '2'];
xlswrite([Filename(1:end-4) '.xlsx'],cell(vars(n)),sheet, xlRange)
xlswrite([Filename(1:end-4) '.xlsx'],eval(char(vars(n))),sheet, xl_range)
end
cillian thomas
2023 年 5 月 4 日
A better way is to put the variables in a matrix, and export the data. See this thread:
xout1 = [1 2 3]
yout1 = [4 5 6]
m = [xout1,yout1]
csvwrite('filename.csv',m)
カテゴリ
ヘルプ センター および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!