reading n columns and n rows from a file

4 ビュー (過去 30 日間)
Shivik Garg
Shivik Garg 2018 年 7 月 2 日
回答済み: Paolo 2018 年 7 月 2 日
0,-69.1127,-68.9,-65.2096,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-66.5,-2,-2,-2,0,0,0
0.027,-69.1062,-68.8937,-65.2083,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-66.4966,-2,-2,-2,0,0,0
0.054,-69.0996,-68.8874,-65.2069,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-66.4933,-2,-2,-2,0,0,0
0.081,-69.0931,-68.8811,-65.2056,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-66.4899,-2,-2,-2,0,0,0
0.108,-69.0865,-68.8747,-65.2043,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-66.4866,-2,-2,-2,0,0,0
0.135,-69.08,-68.8684,-65.2029,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-66.4833,-2,-2,-2,0,0,0
0.162,-69.0735,-68.8621,-65.2016,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-66.48,-2,-2,-2,0,0,0
0.189,-69.067,-68.8559,-65.2003,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-66.4766,-2,-2,-2,0,0,0
0.216,-69.0605,-68.8496,-65.1989,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-66.4733,-2,-2,-2,0,0,0
0.243,-69.054,-68.8433,-65.1976,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-66.47,-2,-2,-2,0,0,0
i want to read n lines and n columns from a file starting from line that reads 0.135 My output should look like this
-69.08,-68.8684,-65.2029,-66.4833
-69.0735,-68.8621,-65.2016,-66.48
-69.0605,-68.8496,-65.1989,-66.4733
-69.054,-68.8433,-65.1976,-66.47
  1 件のコメント
Paolo
Paolo 2018 年 7 月 2 日
Can you please remove the first block of code and add the text file instead?

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

回答 (1 件)

Paolo
Paolo 2018 年 7 月 2 日
Save your .txt file as file.dat. Then use:
mydata = csvread('file.dat');
[row,col]=find(ismembertol(mydata,0.1350));
n = 4;
mymatrix = mydata(row+1:row+n,col+1:col+n);

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by