returning a unique array and comparing it with a different array.
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a code that generates the y-coordinates of a few points, and returns the matrix as follows.
y_cosnode =
0.5833 0.6667 0.7500 0.8333 0.9167 1.0000
0.5000 0.5833 0.6667 0.7500 0.8333 0.9167
I wanted non-repeating values so I used y_cosnode = reshape(unique(y_cosnode),1,[]) . This gives me
y_cosnode =
0.5000 0.5833 0.6667 0.7500 0.8333 0.9167 1.0000
Now, I have another matrix array, a = [0.5000 0.5833 0.6667 0.7500 1] which I would like to compare each entry values with y_cosnode.
for i=1:size(y_cosnode,2)
[row,col] = find(y_cosnode(1,i)==a(1,:));
col
end
col =
1
col =
1x0 empty double row vector
col =
1x0 empty double row vector
col =
4
col =
1x0 empty double row vector
col =
1x0 empty double row vector
col =
5
obviously, 0.5833 and 0.6667 should not be empty because they are in matrix a. However, when I replace the matrix array 'y_cosnode', with
y_cosnode = [0.5000 0.5833 0.6667 0.7500 0.8333 0.9167 1.0000] which are the same values, just typed by myself, I get the following results. Which is what I'm looking for.
col =
1
col =
2
col =
3
col =
4
col =
1x0 empty double row vector
col =
1x0 empty double row vector
col =
5
1 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!