Effacer les filtres
Effacer les filtres

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

131 vues (au cours des 30 derniers jours)
Agnese Manzoni
Agnese Manzoni le 10 Mai 2015
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 commentaires
Nick Earnhardt
Nick Earnhardt le 10 Mai 2015
Modifié(e) : Nick Earnhardt le 10 Mai 2015
What's the question exactly?
You want to turn a mat file to csv file?! or ?
Sorry I'm confused
Have a look at
csvwrite()
and
csvread();
to turn the mat files to csv
Jan
Jan le 10 Mai 2015
Please explain the difference between "load" and "read" and where does the conversion appear?

Connectez-vous pour commenter.

Réponses (3)

mansour torabi
mansour torabi le 1 Oct 2021
In matlab, to write a table to a csv file, use:
load('YourTableData.mat')
writetable(YourTableData, 'FileName.csv')
  1 commentaire
Mudassir shakeel
Mudassir shakeel le 26 Oct 2022
Thanks mansour torabi, it works

Connectez-vous pour commenter.


Abhiram Bhanuprakash
Abhiram Bhanuprakash le 12 Mai 2015
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 commentaires
yasser nasser
yasser nasser le 25 Avr 2021
Error using csvwrite (line 47)
Cannot open file test.csv.
How can solve it?
Walter Roberson
Walter Roberson le 25 Avr 2021
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);

Connectez-vous pour commenter.


Ben Salem Youssef
Ben Salem Youssef le 29 Déc 2017
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 commentaires
Image Analyst
Image Analyst le 29 Déc 2017
load() loads .mat files and other data files, not m-files. You cannot do
s = load(Untitled5.m');
to run your m-file, you just click the green Run tool button on the toolbar, or type F5 function key.
Read this link then start your own question and attach your .mat file with the paper clip icon.
Walter Roberson
Walter Roberson le 29 Déc 2017
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by