How to load data with segments

4 visualizzazioni (ultimi 30 giorni)
JZ
JZ il 21 Set 2021
Commentato: Mathieu NOE il 22 Set 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

Risposta accettata

Mathieu NOE
Mathieu NOE il 21 Set 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 Commenti
JZ
JZ il 22 Set 2021
That's brilliant! Thank you so much!
Mathieu NOE
Mathieu NOE il 22 Set 2021
my pleasure !

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Import and Analysis in Help Center e File Exchange

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by