I have a 1000X1000 matrix in a .txt. How do I parse it into a matrix in matlab?

2 ビュー (過去 30 日間)
Emmanuel
Emmanuel 2016 年 10 月 21 日
コメント済み: KSSV 2016 年 10 月 21 日
My code here doesn't work. Attached in this image below is a example of 2X1000 matrix from a .txt file. I need to parse 1000X1000 numbers into 1000X1000 matrix in matlab.
For Example, the image given below is a .txt file. I need a parser That reads N and assigns N=4, Reads R, assigns R=[0,0]. Reads T, assigns T= [3,3; 2,3; 1,3; 1,3; 1,2; 2,2; 3,2; ]
Reads B and assigns B = [1,3,5,1; 4,1,2,10; 3,2,6,1000; 1,2,3,5]
Could someone guide me on how to do it? Thanks!!

回答 (1 件)

KSSV
KSSV 2016 年 10 月 21 日
Try the below code:
nx = 1000 ; ny = 1000 ;
txtfile=fopen('yourtxtfile','r'); % Open file
% Read matrix
[data,count] = fscanf(grdfile, '%f', [nx,ny]);
fclose(txtfile);
  6 件のコメント
Emmanuel
Emmanuel 2016 年 10 月 21 日
Image attached below is the .txt file I have attached in my Question after editing. I would like to parse variables in matlab. For example: N=4, R = [0,0] etc.,
KSSV
KSSV 2016 年 10 月 21 日
Read about fscanf..

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

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by