How to convert a data Table from .mat to .csv

조회 수: 304(최근 30일)
Agnese Manzoni
Agnese Manzoni 2015년 5월 10일
답변: mansour torabi 2021년 10월 1일
Let's do an example: I have a file called Pippo.mat To load in matlab I use this function: load('Pippo.mat')
How can I let matlab read Pippo.mat? Thank you.
  댓글 수: 2
Jan
Jan 2015년 5월 10일
Please explain the difference between "load" and "read" and where does the conversion appear?

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

답변(3개)

Abhiram Bhanuprakash
Abhiram Bhanuprakash 2015년 5월 12일
Hi Agnese,
Guessing from the title of your question, I think you want to load a MAT file into the MATLAB workspace and convert it to a CSV file, which you want to use it for further processing.
If this is the case, you can follow this workflow. Let's say we have a MAT file 'abc.mat' (attached), which contains two matrices and you want to load the two matrices into MATLAB and create a CSV from the concatenated matrix:
load('abc.mat');
%Concatenate matrices A and B
C = [A, B];
%Write CSV file
csvwrite('test.csv',C);
The created CSV file 'test.csv' is also attached. You can then use 'csvread' if you need to read from the created CSV file. The doc for csvread is here
Hope this helps
Cheers!
Abhiram
  댓글 수: 2
Walter Roberson
Walter Roberson 2021년 4월 25일
You do not have write access to your current directory. You should either cd() to a directory that you do have write access to, or else you should give the path to a location you do have write access to, such as
csvwrite('C:\Users\Yasser\Documents\MATLAB\Project3\test.csv', data_to_write);

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


Ben Salem Youssef
Ben Salem Youssef 2017년 12월 29일
hello everyone , i have problem with command "load": i have a file that called "Untitled5". and i want to load this file then i could use it and import it and use it for the Machine Learning, but i receive this error : Error using load Number of columns on line 2 of ASCII file Untitled5.m must be the same as previous lines. Any Idea please ?? Thank you
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 12월 29일
Can you attach the file?
Your use of .m as an extension hints the file might be MATLAB code, but you would execute MATLAB code instead of load()'ing it.

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


mansour torabi
mansour torabi 2021년 10월 1일
In matlab, to write a table to a csv file, use:
load('YourTableData.mat')
writetable(YourTableData, 'FileName.csv')

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by