Set points that matches with a vector as NaN

2 次查看(过去 30 天)
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.

采纳的回答

Dave B
Dave B 2021-8-12
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 个评论
Philippe Corner
Philippe Corner 2021-8-12
Thank you very much for your help. And this approah using interp1 is very interesting idea to solve this task.
Best wishes!
Philippe Corner
Philippe Corner 2021-8-17
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by