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
Mathieu NOE 2021년 2월 2일
hello
maybe you should also share the data....
tx
Maclane Keohane
Maclane Keohane 2021년 2월 2일
I just added the data. Please try to help me out. I'd like to learn how to use Matlab to help me with this skill. I can easily do it by hand, but thats not the point when I have matlab available

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

 채택된 답변

dpb
dpb 2021년 2월 2일
편집: dpb 2021년 2월 3일

0 개 추천

If I understand what you're after from the code that doesn't quite work--
plot(pro(:,1),pro(:,2))
hold on
iz=arrayfun(@(z)find(z>=pro(:,2),1),zp);
plot(pro(iz,1),zp,'r*-')
legend('Full data set','Nearest @ ZP')
yields
ADDENDUM:
Another "trick" for such problems is to use interp1 backwards -- that is, use the ordinal position of the elements in the array as th y output instead of the more usual "t'other way 'round"
>> interp1(pro(:,2),1:size(pro,1),zp,'nearest')
Error using griddedInterpolant
The grid vectors must contain unique points.
Error in interp1 (line 151)
F = griddedInterpolant(X,V,method);
>>
This isn't an uncommon event with data; interp1 requires that the interpolant be unique; can handle in various ways; either add just a little random noise that is small in size compared to the data to "fuzzy it up" or just pick the unique ones. We'll use the latter method here--
[~,ia]=unique(pro(:,2));
iz=interp1(pro(ia,2),1:size(ia),zp,'nearest')+(size(pro,1)-numel(ia));
hL=plot(pro(iz,1),zp,'g*');
xlim([120 250])
will show almost the identical locations; one off in a couple places where the nearest zp value is the second in the range instead of the first.

추가 답변 (1개)

dpb
dpb 2021년 2월 2일
편집: dpb 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

I do not think I'm forgetting anything. I'm glad you understand what I'm asking though!
There are two colums with 401 rows in the pro double (This plots the bathymetry)
The first column is distance = (:,1) Distance increases as index increases
The second column is depth=(:,2) elevation decreases as index increases
%When I refer to pro(j,2) Im referering to, lets say, -5meters.
%When I refer to pro(j+1,2) Im refering to, lets say, -6meters.
%When I refer to zp(i) Im refering to, lets say -5.5meters
pro(j,2) > zp(i) && pro(j+1,2) < zp(i)
%so -5 > -5.5 & -6 < -5.5
Zp 1x9 double also decreases as index increases = something like [ 0 -2 -3 -4 -5.5 ....]
Thank you for the & operator though (I was unsure)
Let me know what you or anyone thinks!
dpb
dpb 2021년 2월 2일
I think you're still not thinking correctly about the sign sense of comparisons with negative numbers... :)

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2021년 2월 2일

편집:

dpb
2021년 2월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by