Borrar filtros
Borrar filtros

cellarray which contains different types of data

44 visualizaciones (últimos 30 días)
sermet el 13 de Mayo de 2014
Comentada: sermet el 13 de Mayo de 2014
belows came from the results from codes in editor page;
txt1 =
%txt1 10x1 1202 cell global
cc =
%cc 4x1 482 cell global
% I need to use ismember or getname function for searching cc rows into txt1 rows like; [row,col] = ismember(txt1,cc) but it works same data type. Is there any solution I can apply or is there any way to transform txt1 and cc matrixes like that;
%in here, ismember function(ismember(txt1,cc)) works properly.

Respuesta aceptada

Jos (10584)
Jos (10584) el 13 de Mayo de 2014
A = {'text', 1000, 2000, 'data'}
A_as_strings = cellfun(@num2str, A, 'un', 0)
and then you can use ismember ...

Más respuestas (2)

Benjamin Avants
Benjamin Avants el 13 de Mayo de 2014
If you're only trying to verify if the entries in cc appear in txt1, you can start by identifying which entries of txt1 are 'char' data type. The inverse of this would be the numerical entries, assuming there are only string and numerical entries.
strInd = false(size(txt1);
for ii = 1:numel(txt1)
strInd(ii) = ischar(txt{ii});
Then do the same for cc and use ismember on the two subsets.
test1 = ismember(cc{strInd2},txt1{strInd});
test2 = ismember(cc{~strInd2},txt1{~strInd});
If you need to know which entries in cc are not in txt1, you can extract them as follows:
temp = cc{strInd2};
textNotFound = temp{~test1};
temp = cc{~strInd2};
numNotFound = temp{~test2};
This may not be the best approach, but it should work. The for loops are not ideal, but I don't know a faster way.
  1 comentario
sermet el 13 de Mayo de 2014
it is a little complicated any other solution would be welcomed.

Iniciar sesión para comentar.

Benjamin Avants
Benjamin Avants el 13 de Mayo de 2014
In response to your comments, here is one way to convert cell arrays with different data types to a single type.
You can use a loop with the num2str() function. If the function is passed a string it will return the same string. If it is passed a number, it will return that number as a string.
ans = 'p4505'
and = '4505'
So you can convert your cell array as follows:
for ii = 1:numel(txt1)
txt1{ii} = num2str(txt1{ii});
Which will result in txt1 being entirely strings.
You can do the same for the other array and then use ismember to compare them.


Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by