フィルターのクリア

How to determine array equality ?

1 回表示 (過去 30 日間)
x y
x y 2015 年 11 月 30 日
コメント済み: Guillaume 2015 年 11 月 30 日
hy I want to in main while cycle search for point with random searching 'robot'. If the robot see the point what is not in the list, then should put the coordinate to the list...if this point does not contain. I can't figure out how to comparate... I tried different way, the last what I did is this,but I need something like do in for loop,what is going through the matrix rows.
templist = [1 2 0
2 2 0
45 5 0
4 5 1
7 85 0
4 5 1]
newcordinate = [ 4 5 ]
LIST = [];
% sum( [zoznam(:,1) zoznam(:,2)]' )
if sum(newcordinate') == sum( [templist(:,1) templist(:,2)]' )
display('do nothing')
else
templist(end+1)= newcordinate(1,2);
templist(end+1)= newcordinate(1,1);
templist(end+1)= 0;
LIST = reshape(templist,3,[])'
end
the third element is need in the further to determine is the coordinate is used or not

採用された回答

Guillaume
Guillaume 2015 年 11 月 30 日
Possibly, this is what you want:
templist = [1 2 0
2 2 0
45 5 0
4 5 1
7 85 0
4 5 1]
newcoordinate = [4 5]
if ismember(newcoordinate, templist(:, [1 2]), 'rows')
display('do nothing');
else
templist(end+1, :) = [newcoordinate, 0];
end
  2 件のコメント
x y
x y 2015 年 11 月 30 日
編集済み: x y 2015 年 11 月 30 日
Yes, Thank you :)
in the begining the list is empty, so I need to set
templist= [0 0 0]
and at 'templist(end+1, :) = [newcoordinate, 0];'
I have error,
Dimensions of matrices being concatenated are not consistent.
Guillaume
Guillaume 2015 年 11 月 30 日
It would be better to initialise templist with
templist = zeros(0, 3);
I cannot reproduce your second error. Are you sure that newcoordinate is a 1x2 vector?

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by