how to choose right index

2 ビュー (過去 30 日間)
imola
imola 2015 年 2 月 16 日
コメント済み: imola 2015 年 2 月 16 日
Dear All,
I have this matrix X and this is the index for it. I want to take the row with 1 1 index to empty and plot the remind points, but I got wrong
Y =[1.7797 1.3341
1.5067 0.5390
1.0709 1.0732
1.2872 1.0745
0.3687 1.4166
0.4112 0.2333
1.4512 0.8961
1.9749 1.6645];
idx =[0 1
0 1
1 1
1 1
0 1
0 0
1 1
0 0];
m=8;
for i=1:1:m
if idx(i,1:1:end)==1
Y(i,:)=[]
end
m=size(Y,1)
end
plot(Y(:,1),Y(:,2),'.r');
I know my problem with the if condition, I don't know who to write it correct. Can anyone help me please.
Regards, imola
regards
  3 件のコメント
imola
imola 2015 年 2 月 16 日
sorry Geoff,
I change the question hopefully make it simple, I'm stuck here
if idx(i,1:1:end)==1
I think it is wrong, I want to generalize this formula to dim>2 if it succeed here.
Thanks for replying.
Regards
Image Analyst
Image Analyst 2015 年 2 月 16 日
You say "I have this matrix X" - what matrix X???? And if idx(i,1:1:end)==1 gives a vector. I think you want to use all().

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

採用された回答

Image Analyst
Image Analyst 2015 年 2 月 16 日
Perhaps you want this:
clc;
Y =[1.7797 1.3341
1.5067 0.5390
1.0709 1.0732
1.2872 1.0745
0.3687 1.4166
0.4112 0.2333
1.4512 0.8961
1.9749 1.6645];
idx =[0 1
0 1
1 1
1 1
0 1
0 0
1 1
0 0];
[rows, columns] = size(idx)
rowsToKeep = false(rows, 1);
for row=1:1:m
allOnes = all(idx(row, :));
if ~allOnes
rowsToKeep(row) = true;
end
end
rowsToKeep
extractedY = Y(rowsToKeep, :);
plot(extractedY(:,1), extractedY(:,2), 'r.-', 'MarkerSize', 20);
grid on;
  1 件のコメント
imola
imola 2015 年 2 月 16 日
Dear,
thank you very much for your answer. you really saved me. I understood what you did but I want to be sure so I can use the commends in future, so could you please explain it to me.
Many thanks,
Imola.

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

その他の回答 (1 件)

Thorsten
Thorsten 2015 年 2 月 16 日
編集済み: Thorsten 2015 年 2 月 16 日
Y = Y(sum(idx, 2) ~= 2, :);
plot(Y(:,1), Y(:,2), '.r')

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by