MATLAB Answers

how to find data?

1 view (last 30 days)
Samaneh Arzpeima
Samaneh Arzpeima on 3 Jul 2019
Answered: Samaneh Arzpeima on 3 Jul 2019
Hi
please have a look on attached file
I can see the value 2.9377e+03 at index 5414
but the following code does not return anything
please tell me what is wrong, I need to extract all the Ys where Z is 29377
aspdepth=Y(Z==29377);
[aspdepth_sorted,aspdepth_order]=sort(aspdepth);
and I will be grateful and appreciate any fast help
Thank YOU

Answers (2)

Raj
Raj on 3 Jul 2019
Edited: Raj on 3 Jul 2019
First of all 2.9377e+03=2937.7 and not 29377 as you are looking for. So relook into that.
Secondly, i think its just accuracy error. To check this run this:
load('Y.mat')
load('Z.mat')
Z(5414)
aspdepth=Y(Z==ans);
[aspdepth_sorted,aspdepth_order]=sort(aspdepth);
You need to change the data format to get correct result.
  2 Comments
Raj
Raj on 3 Jul 2019
Hello,
1) Since you are looking for "equal or very close" you need to define a tolerance here. How much 'very close' is good enough for your case? Then instead of using '==' you can use a conditional statement something like this
load('Z.mat')
load('Y.mat')
survayline = 12*tand(60);
tolerance_value=10e-3; % Define your tolerance
jj=1;
for ii=1:length(Z)
if abs(Z(ii)-survayline)<tolerance_value
aspdepth(jj)=Y(ii);
jj=jj+1;
end
end
[aspdepth_sorted,aspdepth_order]=sort(aspdepth);
2)
survayline = 12*tand(60)
gives output as survayline = 20.7846. This value is no where close to any values in the Z mat file that you have shared. If the Y and Z mat files that you had shared earlier are also example files, please use correct files or define a large tolerance.

Sign in to comment.


Samaneh Arzpeima
Samaneh Arzpeima on 3 Jul 2019
Now I am confused. I need to have one number to put it instead of 29377,in the following code.the one that I sent at the begining.
aspdepth=Y(Z==29377);
[aspdepth_sorted,aspdepth_order]=sort(aspdepth);
it should be
survayline = (12*tand(60))*1000;
or the closest value.
I couldn't understand what will be the value from your code.
survayline = (12*tand(60))*1000; %I had to multiply by 1000
%tolerance_value=10e-3; % Define your tolerance
tolerance_value=500;
jj=1;
for ii=1:length(Z)
if abs(Z(ii)-survayline)<tolerance_value
aspdepth(jj)=Y(ii);
jj=jj+1;
end
end
[aspdepth_sorted,aspdepth_order]=sort(aspdepth);

Categories

Community Treasure Hunt

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

Start Hunting!