I have a table of measurements and the corresponding depth where the measurements were taken. I'm trying to graph the depth where the difference between two adjacent measurements is larger than a certain value (ex, 1) for the first time (See this question). I find this depth using
list = [];
for t = 1:size(data,1)
y1 = data.depth(find(abs(diff(data(t,:)))>1,1)+1);
list = [list y1];
end
Since my objective is to graph this, I need the list be the same size at data. However, if there is no difference that is greater than one, it does not add anything to the list. This changes the size of list. I tried including
list = [];
for t = 1:size(data,1)
y1 = depth(find(abs(diff(data(t,:)))>1,1)+1);
if y1 == 0
y1 = nan
end
list = [list y1];
end
but this doesn't work because, if there is no adjacent difference is greater than 1, then y1 equals nothing, not zero.
How can I add NaN for every time there is no adjacent difference greater than 1?

 채택된 답변

KSSV
KSSV 2020년 6월 22일

1 개 추천

May be your should add
if isempty(y1)
y1 = NaN;
end

댓글 수: 3

Camille Woicekowski
Camille Woicekowski 2020년 6월 22일
Awesome, isempty() is the command I needed.
Thank you so much!
KSSV
KSSV 2020년 6월 22일
Thanks is accepting/ voting the answer ..:)
Camille Woicekowski
Camille Woicekowski 2020년 6월 22일
Done :)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 6월 22일

댓글:

2020년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by