reading large text files into matrix

4 ビュー (過去 30 日間)
Nitish Reddy Kotkur
Nitish Reddy Kotkur 2019 年 10 月 20 日
回答済み: Stephan 2019 年 10 月 21 日
im trying to read a text file containing matrix
A = readmatrix('output1.txt','Whitespace',' []'); when i execute it
its displaying
NaN NaN
NaN NaN
NaN NaN
NaN NaN
here output1.txt file contains data in the given manner
[[0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 0 1]
[0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0]]-50*50
what else changes can i make .
BTW it worked fine when matrix size is low i.e when every row of matrix is displayed in single line but as size of matrix increases single row is being displayed in multiple lines thats when problem arised.
i have attached the text file.
can some one modfy this A = readmatrix('output1.txt','Whitespace',' []');
so it can read matrix from the file irrespective of how large it is.
  4 件のコメント
dpb
dpb 2019 年 10 月 20 日
If going to do it that way, though, might as well just use .mat file format.
It's not clear the "why" behind this scheme so hard to generalize best solution -- but the one started down is probably not it.
Turlough Hughes
Turlough Hughes 2019 年 10 月 20 日
I somehow doubt the data was generated in matlab. My comment is just to demo how easy it is to read data similar to Nitish's if it's formatted beforehand.

サインインしてコメントする。

回答 (1 件)

Stephan
Stephan 2019 年 10 月 21 日
As already stated in the other question you asked with the same content, a possible way is:
A = readcell('output1.txt');
B = str2num(char(replace(split(string([A{:,1}]),']'),...
{'00', '10', '01', '11', '['},{'0 0', '1 0', '0 1', '1 1', ''})));

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by