How to load data with segments

조회 수: 3 (최근 30일)
JZ
JZ 2021년 9월 21일
댓글: Mathieu NOE 2021년 9월 22일
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

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 9월 21일
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
JZ
JZ 2021년 9월 22일
That's brilliant! Thank you so much!
Mathieu NOE
Mathieu NOE 2021년 9월 22일
my pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by