Set points that matches with a vector as NaN

load('var.mat')
scatter3(cy(:,1),cy(:,2),cy(:,3),10,'k','filled');hold on
scatter3(top(:,1),top(:,2),top(:,3),10,'r','filled');
scatter3(bot(:,1),bot(:,2),bot(:,3),10,'r','filled');
whos cy
Name Size Bytes Class Attributes cy 46057x4 1473824 double
cy is a 4 columns matrix, I would like to set all the values of cy(:,4) that matches with the positiones above top vector and below bot vector as NaN values.

 Accepted Answer

In this particular case, because they all have the same y value, you can do this quite easily with interp:
scatter3(cy(:,1),cy(:,2),cy(:,3),10,'k','filled');hold on
scatter3(top(:,1),top(:,2),top(:,3),10,'r','filled');
scatter3(bot(:,1),bot(:,2),bot(:,3),10,'r','filled');
ind = cy(:,4) < interp1(bot(:,1),bot(:,3),cy(:,1)) | ...
cy(:,4) > interp1(top(:,1),top(:,3),cy(:,1));
cy(ind,4) = nan;
scatter3(cy(:,1),cy(:,2),cy(:,4),10,'m','filled');hold on

6 Comments

Hi Dave,
I did not undertand your approach.. it did not work actually.
There are some points in cy(:,3) matrix with values in cy(:,4). These points are located in [cy(:,1) cy(:,2) cy(:,3)] above and below [top(:,1) top(:,2) top(:,3)] and [bot(:,1) bot(:,2) bot(:,3)] , im trying to change the cy(:,4) values that matches these conditions to NaN.
The way that i understood your problem was that you have top which contains x,y,z co-ordinates for a top, and bot which contains x,y,z co-ordinates for a bottom.
Looking at your data, it was clear that the y values were irrelevant: all of the values are the same plane.
So I used interp1 to find the relvant z value for each x value. The expression:
interp1(bot(:,1),bot(:,3),cy(:,1))
says to find the z co-ordinate of the bottom by interpolating, using the x cordinate in cy and the mapping of x to z established in bot.
Below I've attached the result (I had to re-include the file): you can see that the values of cy(:,4) which are above and below top and bot have been removed.
load('var.mat')
scatter3(cy(:,1),cy(:,2),cy(:,3),10,'k','filled');hold on
scatter3(top(:,1),top(:,2),top(:,3),10,'r','filled');
scatter3(bot(:,1),bot(:,2),bot(:,3),10,'r','filled');
ind = cy(:,4) < interp1(bot(:,1),bot(:,3),cy(:,1)) | ...
cy(:,4) > interp1(top(:,1),top(:,3),cy(:,1));
cy(ind,4)=nan;
scatter3(cy(:,1),cy(:,2),cy(:,4),10,'m','filled');hold on
Thanks a lot for your kind dispositon Dave,
Maybe I did not express myself properly. So, if we plot the cy matrix like this:
load('var.mat')
scatter3(cy(:,1),cy(:,2),cy(:,3),10,'k','filled');hold on
scatter3(cy(:,1),cy(:,2),cy(:,3),10,cy(:,4),'filled');% with the cy(:,4) values that we want to set NaN
scatter3(top(:,1),top(:,2),top(:,3),10,'r','filled');
scatter3(bot(:,1),bot(:,2),bot(:,3),10,'r','filled');
you can see that above the top and below the bottom, there are some cy(:,4) values. I want to use indexes to find the positions and change them to NaN so all the plot:
scatter3(cy(:,1),cy(:,2),cy(:,3),10,cy(:,4),'filled');% with the cy(:,4) values that we want to set NaN
set the cy values only inside top and bot boundaries.
Thanks a lot!
@Philippe Corner - Sorry that was totally my fault. I was incorrectly thinking about the matrix in the cy matrix.
I was checking cy(:,4) against bot(:,2)/top(:,3) but I think the answer is basically the same but I should have been checking against cy(:,3) - which in hindsight makes a lot of sense! Is this the correct cropping?
load('var.mat')
scatter3(cy(:,1),cy(:,2),cy(:,3),10,'k','filled');hold on
scatter3(top(:,1),top(:,2),top(:,3),10,'r','filled');
scatter3(bot(:,1),bot(:,2),bot(:,3),10,'r','filled');
ind = cy(:,3) < interp1(bot(:,1),bot(:,3),cy(:,1)) | ...
cy(:,3) > interp1(top(:,1),top(:,3),cy(:,1) ,'nearest');
cy(ind,4)=nan;
scatter3(cy(:,1),cy(:,2),cy(:,3),10,cy(:,4),'filled');hold on
Thank you very much for your help. And this approah using interp1 is very interesting idea to solve this task.
Best wishes!
Hi Dave, this quiestion is very similar tham this one, but im confused about how to use it for all X, Y, Z positons. If you can give a hand it would be highly appreciated! https://it.mathworks.com/matlabcentral/answers/1413272-how-to-change-the-c-values-that-matches-a-3-coordinates-position-condition

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!