Is it possible to find corresponding row from other matrix's row??

1 回表示 (過去 30 日間)
Triveni
Triveni 2016 年 3 月 8 日
コメント済み: Triveni 2016 年 3 月 9 日
y = [ 90 90 -45 0 0 45 45 0 -45 15 15;
90 90 -45 0 0 45 45 0 -45 15 15;
90 90 -45 0 0 45 45 0 -45 15 0;
90 90 -45 0 0 45 45 0 -45 15 0;
90 90 -45 0 0 45 45 0 -45 15 15;
90 90 -45 0 0 45 45 0 -45 15 15;];
y0 = sort(y,2);
y = y(sum([ones(size(y,1),1),diff(y0,[],2)~=0],2) >= numel(unique(y)),:);
y = permute(y ,[3 2 1]);
for k = 1:size(y,3)
[x0(:,:,k), x00(:,:,k)] = hist(y(:,:,k), unique(y(:,:,k)));
end
x0 =permute(x0,[3 2 1]); x00 =permute(x00,[3 2 1]);
x0(any(x0<2,2),:) = [];
I have to find corresponding row of "x00"
  2 件のコメント
Matthew Eicholtz
Matthew Eicholtz 2016 年 3 月 8 日
Your question is a little confusing. Can you try rewording for clarity?
Where do you actually need help? In the last part?

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

採用された回答

Stephen23
Stephen23 2016 年 3 月 9 日
編集済み: Stephen23 2016 年 3 月 9 日
It is easy, you just need to assign the logical conditions to an index variable. So instead of this:
x0(any(x0<2,2),:) = [];
you should allocate that logical condition to a variable:
idx = any(x0<2,2);
and then you can use idx for any of the matrices:
>> xdel = x0(idx,:)
xdel =
2 4 1 2 2
2 4 1 2 2
>> xnew = x0(~idx,:)
xnew =
2 3 2 2 2
2 3 2 2 2
2 3 2 2 2
2 3 2 2 2
and now you can try x00(idx,:) and x00(~idx,:) yourself!
  2 件のコメント
Triveni
Triveni 2016 年 3 月 9 日
Ya right...Thank you. ...
Triveni
Triveni 2016 年 3 月 9 日
y = [ 90 90 -45 0 0 45 45 0 -45 15 15;
90 90 -45 0 0 45 45 0 -45 15 15;
90 90 -45 0 0 45 45 0 -45 15 0;
90 90 -45 0 0 45 45 0 -45 15 0;
90 90 -45 0 0 45 45 0 -45 15 15;
90 90 -45 0 0 45 45 0 -45 15 15;];
y0 = sort(y,2);
y = y(sum([ones(size(y,1),1),diff(y0,[],2)~=0],2) >= numel(unique(y)),:);
y = permute(y ,[3 2 1]);
for k = 1:size(y,3)
[x0(:,:,k), x00(:,:,k)] = hist(y(:,:,k), unique(y(:,:,k)));
end
x0 =permute(x0,[3 2 1]); x00 =permute(x00,[3 2 1]);
y = permute(y ,[3 2 1]);
idx = any(x0<2,2);
xdel = x0(idx,:)
xnew = x0(~idx,:)
y = y(~idx,:)

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

その他の回答 (1 件)

Ced
Ced 2016 年 3 月 8 日
編集済み: Ced 2016 年 3 月 8 日
I am not sure I understood the full question, but in short, you want to delete rows in which there is an element < 2 ? You basically already answered the question. Since you like one liners, I think this should do the trick:
x(any(x<2,2),:) = [];
This finds all rows (DIM 2) in which there is ANY element smaller than 2, selects these rows, and deletes them.
If you want to match your centers, you can do:
rows_del = any(x<2,2);
x(rows_del,:) = [];
z(rows_del,:) = [];

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by