writematrix output file that can't be read by textread

7 次查看(过去 30 天)
I am using writematrix to write a 2D matrix to csv, and read this csv later elsewhere (e.g., Python Numpy).
The problem is that this file always errors, even when I read this file using textread.
Would you please help me?
Here is a sample code to reproduce the issue:
filename_ = 'sample_matrix.csv';
writematrix(rand(20,30), filename_);
textread(filename_) % this errors

采纳的回答

Walter Roberson
Walter Roberson 2023-4-17
The format specification is mandatory for textread
Perhaps you wanted readmatrix or readlines or fileread
  4 个评论
Mahmoud Elzouka
Mahmoud Elzouka 2023-4-18
When I changed the encoding to 'windows1251', the file can be read by numpy.loadtxt. Thanks for your help.
FYI, this still errors:
filename_ = 'windows1251.csv';
writematrix(rand(20,30), filename_, 'Encoding', 'windows1251');
textread(filename_) % this errors
Walter Roberson
Walter Roberson 2023-4-18
textread must be given at least two parameters. textread is for reading formatted data and you have to tell it the format. textread is not for reading a file as a single character vector: I already gave links to two routines for that.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by