Matlab 用于比较两个单元阵列的函数

Matlab 用于比较两个单元阵列的函数,matlab,Matlab,我有一个单元格数组(2000*10),每个单元格包含一个字符串,如'25:20:55' 我想编写一个函数,它接受10个输入(比如'25:02:33','58:69:88','25:54:96','48:58:36','58:54:88'等等),并在每个列中查找与该特定列的输入值对应的匹配项(即,第一输入数据对应于存储数据的第1列、第2至第2列,依此类推 如何编写用于上述比较的函数?假设单元格数组包含字符串,可以使用strcmp查找匹配项: input = {'25:02:33', '58:69:

我有一个单元格数组(2000*10),每个单元格包含一个字符串,如
'25:20:55'

我想编写一个函数,它接受10个输入(比如
'25:02:33'
'58:69:88'
'25:54:96'
'48:58:36'
'58:54:88'
等等),并在每个列中查找与该特定列的输入值对应的匹配项(即,第一输入数据对应于存储数据的第1列、第2至第2列,依此类推


如何编写用于上述比较的函数?

假设单元格数组包含字符串,可以使用strcmp
查找匹配项:

input = {'25:02:33', '58:69:88', '25:54:96', '48:58:36', '58:54:88'};
match_idx = strcmp(repmat(input, size(cell_data,1),1), cell_data);
如果您只想知道各个列中是否有匹配项,而不关心匹配项的行索引,则可以这样做

match = any(match_idx,1);

使用
ismember

ismember(your_var, your_cell);
e、 g

在你的情况下,类似这样的东西可能会起作用

function arr = myfun(inputvec, inputmat)
for i=1:length(inputvec) %// where inputvec is the cell-vector with the strings you want to search for
   arr(i) = ismember(inputvec{i}, inputmat{:,i});
end

单元格中是否包含“25:20:55”之类的字符串,或者您是说单元格中是否包含类似
[25,20,55]
之类的数组?它包含类似“25:20:55”之类的字符串
function arr = myfun(inputvec, inputmat)
for i=1:length(inputvec) %// where inputvec is the cell-vector with the strings you want to search for
   arr(i) = ismember(inputvec{i}, inputmat{:,i});
end