How to Fit Points on a Previous Plot
이전 댓글 표시
I have a 401x2 double that plots the bythmetry of a beach.
I have 9 depth positions of sensors on the bottom with data provided in a 1x9 double.
I want to plot the sensors on the bythmetry plot. The depth of sensors don't directly match up with the value of depths given in the 401x2 double.
%(pro=bythymetry 401x2) (zp=depth of sensors 9x1)
plot(pro(:,1),pro(:,2)) %(distance,depth) ,depth decreases as you go below sea level (-#)
for i = length(zp)
for j = length(pro(:,2))
if pro(j,2) > zp(i) && pro(j+1,2) < zp(i) %find estimated distance where the depth occurs
hold on
plot(pro(j,1),zp(i))
end
end
end
I could use some help. Anyway I try to write a nested for loop with a conditional statement, I don't get any values! Advice on interpolating and plotting would be helpful
plot(pro(:,1),pro(:,2))
this gives

EDIT: I ATTACHED THE DATA AND A FILE TO HELP YOU UNDERSTAND THE DATA (Try it for yourselves might be fun - theres a sand bar)
댓글 수: 2
Mathieu NOE
2021년 2월 2일
hello
maybe you should also share the data....
tx
Maclane Keohane
2021년 2월 2일
채택된 답변
추가 답변 (1개)
I'm betting you're forgeting your above note that increasing depths are larger negative numbers and have something like the following for a given iteration...indices removed for ease in reading--
pro=[-90 -110]; % a set of depths in the profile table
zp=-100; % a sampled data point; should be between given depths
Your code as written is--
>> pro(2)>zp & pro(1)<zp
ans =
logical
0
>>
which fails. What's going on?
Substituting values the above expression is
pro(2)> zp & pro(1)< zp
(-110 >-100) & (-90 < -100)
ans =
logical
0
You're forgetting that the order is increasing going down in depth but up in the indices of the stored array locations in the 2-vector in profile.
Either swap pro(2) and pro(1) or change the direction of the tests in the above expression or wrap each element in the expression inside abs()
Also NB: you want the "&" operator here, not "&&"
댓글 수: 2
Maclane Keohane
2021년 2월 2일
dpb
2021년 2월 2일
I think you're still not thinking correctly about the sign sense of comparisons with negative numbers... :)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
