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.

3 次查看(过去 30 天)
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: { 1x1 double 1x1 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'};
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)
dup = strcat(duplicates(e),'_i');
build8data_names{1,1}{str2num(testnum)} = dup;
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);

更多回答(0 个)




Community Treasure Hunt

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

Start Hunting!

Translated by