Filter löschen
Filter löschen

How to load data with segments

2 Ansichten (letzte 30 Tage)
JZ
JZ am 21 Sep. 2021
Kommentiert: Mathieu NOE am 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

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 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 Kommentare
JZ
JZ am 22 Sep. 2021
That's brilliant! Thank you so much!
Mathieu NOE
Mathieu NOE am 22 Sep. 2021
my pleasure !

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by