How to convert .mat file to .csv file without corrupting the data?
9 views (last 30 days)
Show older comments
Abdullah Özkan
on 11 Jan 2022
Commented: Cris LaPierre
on 14 Jan 2022
Hi,
I have a matrix of 1920x1631 without a single null cell. When I use
writematrix(MatrixName,'FileName.csv')
it gives me a csv file. However, when I examine the file, I noticed my data was corrupted. For instance, the first row contains only 20 column instead of 1631 which is the column number of the original matrix. Do you have any suggestion? Is it possible the problem occurs due to my values on the matrix (values are very small and some of them are negative)? Thank you in advance.
7 Comments
Cris LaPierre
on 11 Jan 2022
Edited: Cris LaPierre
on 11 Jan 2022
I just used your mat file and code, and the csv file had the correct number of columns. I also used repmat to expand your shared variable to have size 1920x1820. When opening in Excel, it also had 1820 columns. However, I'm using desktop. I tested in R2022a prerelease. What version of MATLAB are you using?
You mention having to dowload the csv file. Are you using MATLAB Online? How are you downloading it?
I did run the same tests in MATLAB Online (current version is R2021b), and then downloaded the csv file. It had 1820 columns, too.
Are there any more details you can provide? Are you omitting any code?
One observation - you second screenshot is showing a mix of periods and commas. It looks like periods are your decimal separator when there is no scientific notation (E05, for example) and a comma when there is. I've included a couple examples of each below.
What do you see if you open the csv file in a text editor like notepad instead of Excel?
Jan
on 11 Jan 2022
@Abdullah Özkan: Do I understand correctly, that the actual problem is, that Excel does not import the CSV file correctly?
The actual data cannot cause the problem, so does this reproduce the error on your computer:
Matrix = rand(1920, 1631);
writematrix(Matrix,'FileName.csv');
By the way: "matrices" is the plural of "matrix".
Accepted Answer
Abdullah Özkan
on 14 Jan 2022
1 Comment
Cris LaPierre
on 14 Jan 2022
Since you are already in MATLAB, why not use it for your Machine Learning as well?
More Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!