MATLAB: Error using ismember function: Input A of class cell and input B of class cell must be cell arrays of character vectors, unless one is a character vector.

cell arrayif statementismemberMATLAB

I have a cell array of names with some duplicates. For example, the 1st, 18th and 32nd row of the array contain the same value. I am looking to use each name in the array to create and name a csv file.
Since there are duplicates, I am not able to save a file for each row of the array because each duplicate overwrites the previous file with that name.
My solution was to append an '_i' to the name every time I came accross a duplicate. So if there was a second duplicate, it would be renamed with a '_i_i' at the end of it.
My issue is that the array I am creating, "duplicates", is mixing doubles with cell array values. For example: { 1×1 double 1×1 double {'cell'} }
This is why I added the section of code that says "duplicates(e) = {'none'}". However, it is not filling in those spots with {'none'}. Why isn't this functioning correctly? My apologies in advance for the long tedious explanation.
build8dn = build8dn';
[build8dataname,ia] = unique(build8dn);
for e = 1:length(input_files)
test = input_filenames{e};
testnum = test(1,5:6);
duplicates = {};
if ismember(e,ia)
duplicates(e) = {'none'};
else
build8data_names{1,1}{str2num(testnum)} = strcat(build8data_names{1,1}{str2num(testnum)},'_i');
duplicates(e) = build8data_names{1,1}{str2num(testnum)};
if ismember(duplicates(e),duplicates)
else
dup = strcat(duplicates(e),'_i');
build8data_names{1,1}{str2num(testnum)} = dup;
end
end
build8data_names{1,1}{str2num(testnum)};
filename = strcat(build8data_names{1,1}{str2num(testnum)},'_',bcstr,'.csv');
input_files_new = input_files(e);
input_files_new = cell2mat(input_files_new);
filename = cell2mat(filename);
writematrix(input_files_new,filename);
end

Best Answer

I suggest you keep your logic simple. just append the loop number in your filename, thereby avoiding the complicated logic altogether.