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)

4 views (last 30 days)
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?

Answers (1)

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

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!