How to convert .mat file to .csv file without corrupting the data?
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Cris LaPierre
2022 年 1 月 11 日
編集済み: Cris LaPierre
2022 年 1 月 11 日
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/859625/image.png)
What do you see if you open the csv file in a text editor like notepad instead of Excel?
Jan
2022 年 1 月 11 日
@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".
採用された回答
Abdullah Özkan
2022 年 1 月 14 日
1 件のコメント
Cris LaPierre
2022 年 1 月 14 日
Since you are already in MATLAB, why not use it for your Machine Learning as well?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!