How to load data with segments

5 vues (au cours des 30 derniers jours)
JZ
JZ le 21 Sep 2021
Commenté : Mathieu NOE le 22 Sep 2021
Hi there,
I have a file, looks like below, it's Lon/Lat/Depth separated by ">". I tried to use importdata(), but only got first part. I need to plot some contour lines using geoplot(). Your suggestions will be appreciated.
> -660 contour -Z-660
288.9812 -7.0500 -660.0000
288.9884 -7.1000 -660.0000
288.9958 -7.1500 -660.0000
289.0000 -7.1777 -660.0000
> -660 contour -Z-660
289.0364 -7.4000 -660.0000
289.0454 -7.4500 -660.0000
289.0500 -7.4748 -660.0000
> -660 contour -Z-660
289.0741 -7.6000 -660.0000
289.0843 -7.6500 -660.0000
289.0948 -7.7000 -660.0000
289.1000 -7.7240 -660.0000
289.1056 -7.7500 -660.0000
289.1166 -7.8000 -660.0000

Réponse acceptée

Mathieu NOE
Mathieu NOE le 21 Sep 2021
hello
I copied / pasted your data in a txt file
try this :
%% read one file
clc
clearvars
filename = 'mydata.txt';
data = myreadfunction(filename)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function data = myreadfunction(filename)
a = readlines(filename);
[m,~] = size(a);
data = [];
% find / extract the different sets of data - separated by text "> -660 contour -Z-660"
start_indexes = find(contains(a,'>'))+1;
stop_indexes = [start_indexes(2:end)-2; m];
for ci = 1:length(start_indexes)
tmp = str2num(char(a(start_indexes(ci):stop_indexes(ci)))); % one segment of data
data = [data; tmp];
end
end
it gives :
data =
288.9812 -7.0500 -660.0000
288.9884 -7.1000 -660.0000
288.9958 -7.1500 -660.0000
289.0000 -7.1777 -660.0000
289.0364 -7.4000 -660.0000
289.0454 -7.4500 -660.0000
289.0500 -7.4748 -660.0000
289.0741 -7.6000 -660.0000
289.0843 -7.6500 -660.0000
289.0948 -7.7000 -660.0000
289.1000 -7.7240 -660.0000
289.1056 -7.7500 -660.0000
289.1166 -7.8000 -660.0000
  2 commentaires
JZ
JZ le 22 Sep 2021
That's brilliant! Thank you so much!
Mathieu NOE
Mathieu NOE le 22 Sep 2021
my pleasure !

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by