How to populate a new vector by extracting only certain elements from another vector?

10 ビュー (過去 30 日間)
Loren99
Loren99 2022 年 6 月 15 日
編集済み: Loren99 2022 年 9 月 15 日
Hi everyone!
I would like to obtain two vectors new_vrx (with size 2xn) and new_vry (with size 2xn).
I would like to keep only those segments for which both the starting and ending point coordinates have values Vq1 = 0 and Vq2 = 0.
Vq1 = interp2(Xpix,Ypix,double(M),vrx(1,:),vry(1,:));
Vq2 = interp2(Xpix,Ypix,double(M),vrx(2,:),vry(2,:));
Could you help me? Thanks in advance

採用された回答

Konrad
Konrad 2022 年 6 月 15 日
Hi Loren,
if understood your question correctly, this should do what you want:
load('reticolo2D.mat');
[Xpix, Ypix] = meshgrid(1:321,1:241);
Vq1 = interp2(Xpix,Ypix,double(M),vrx(1,:),vry(1,:));
Vq2 = interp2(Xpix,Ypix,double(M),vrx(2,:),vry(2,:));
new_vrx = vrx(1,Vq1==0);
new_vry = vry(1,Vq1==0);
figure;plot(new_vrx,new_vry,'b-')
and
new_vrx = vrx(2,Vq2==0);
new_vry = vry(2,Vq2==0);
figure;plot(new_vrx,new_vry,'b-')
Best, Konrad
  3 件のコメント
Konrad
Konrad 2022 年 6 月 15 日
I don't understand what your data represents, but how about this:
load('reticolo2D.mat');
[Xpix, Ypix] = meshgrid(1:321,1:241);
Vq1 = interp2(Xpix,Ypix,double(M),vrx(1,:),vry(1,:));
Vq2 = interp2(Xpix,Ypix,double(M),vrx(2,:),vry(2,:));
new_vrx = vrx(:,Vq1==0&Vq2==0);
new_vry = vry(:,Vq1==0&Vq2==0);
figure;plot(new_vrx,new_vry,'b-')
Image Analyst
Image Analyst 2022 年 6 月 15 日
"it doesn't answer my question." <== Well now you've accepted the answer so people will (rightfully?) assume that you have since figured it out.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by