How to convert a .mat file into a .csv file?
2.128 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hello_world
el 30 de Mzo. de 2015
Comentada: Rik
el 25 de Abr. de 2023
Hello Friends,
I have a .mat file loaded in workspace. I want to convert it into .csv file. It has real entries. I used to convert it before using the following commands without any problem:
M = dlmread('FileName.mat', '\t', 1, 0);
csvwrite('FileName.csv', M)
But now something is wrong with MATLAB. My dataset is the same. Nothing has changed, but now it gives the following error:
Error using dlmread (line 139)
Mismatch between file and format string.
Trouble reading number from file (row 1u, field 1u) ==>
}Ûa&Ír!ÃþxbSoÈñæo8k:¬i’³*Y#~!IjË9B¯ÝWG~
¬zN=å0ÉÀo8Ó'Rå@õR[iãY>,xÊ8UrVÀ9ó";~~ÀOWAe$Æ\:xfnFVAÿñϼÓЪÍðaþ\n
I wonder if MATLAB changed something with dlmwrite function! Please advise.
4 comentarios
Image Analyst
el 1 de Mzo. de 2023
@Jose Ocampo I don't know what you mean. When you do
csvwrite('FileName.csv', M)
the file is created in the current directory -- what you see in the directory/address field in MATLAB.
Respuesta aceptada
Más respuestas (3)
Ashlesh Sortee
el 4 de Jul. de 2017
simply you can copy and paste the matrix you want in excel
- all you have to do is open .mat file in matlab , press 'ctr+A' & 'ctr+C' in the variable tab and paste it in new excel sheet
0 comentarios
Ashlesh Sortee
el 4 de Jul. de 2017
Editada: Ashlesh Sortee
el 4 de Jul. de 2017
FileData = load('FileName.mat'); csvwrite('FileName.csv', FileData.FileName);
- | | * This one worked for me||*
- Thanks Jan Simon
Image Analyst
el 30 de Mzo. de 2015
You're trying to save the variable called FileName20.mat in dlmwrite(). If that's the variable, then you have a dot in the name which means that FileName20 must be a structure, and mat must be a field/member of the structure. It's clearly not - you don't have any structure variable in your program called FileName20. You probably need to pass in M instead of FileName20.
2 comentarios
Jan
el 30 de Mzo. de 2015
I do not believe that this has worked before. You cannot read a MAT file by dlmread. MAT files are imported by load.
Image Analyst
el 30 de Mzo. de 2015
I totally agree with Jan. See Jan's answer, then "Accept" it. It loads your file into a structure called FileData. The "M" array that you stored in the mat file will be a "field" of FileData. Then he writes out only that field to your new csv file.
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!