reading n columns and n rows from a file

4 vues (au cours des 30 derniers jours)
Shivik Garg
Shivik Garg le 2 Juil 2018
Réponse apportée : Paolo le 2 Juil 2018
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 commentaire
Paolo
Paolo le 2 Juil 2018
Can you please remove the first block of code and add the text file instead?

Connectez-vous pour commenter.

Réponses (1)

Paolo
Paolo le 2 Juil 2018
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);

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by