필터 지우기
필터 지우기

reading n columns and n rows from a file

조회 수: 1 (최근 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 CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by