Error using cell/ismember (line 34) Input A of class double and input B of class cell must be cell arrays of character vectors, unless one is a character vector. Error in untitled5 (line 190) if ismember(B​W6(i,j),ar​ray1)~= logical(1)

5 次查看(过去 30 天)
Hi I defined array1 as array1={} and I am going to iterate over all elements of a matrix and if the matrix element has not been added to the array1 before, I want to add the elemnt to array1. I wrote the if statement as below but I constantly get error. What is my mistake?Thanks
if ismember(BW6(i,j),array1)~= logical(1)
array1=[array1,BW6(i,j)]
end
I get this error:
Error using cell/ismember (line 34)
Input A of class double and input B of class cell must be cell arrays of character vectors, unless one is a character vector.
Error in untitled5 (line 190)
if ismember(BW6(i,j),array1)~= logical(1)
How can I solve this problem?

回答(1 个)

Steven Lord
Steven Lord 2019-5-23
So you want all the unique elements of the matrix? Use the unique function or if "close enough" counts use the uniquetol function instead.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by