0

I am wondering folks how can I loop over two different data cell arrays.

More precisely, The first

data1 = {'x','y','z', 'xyz','yxz'};
data2 = {'b','c','a'};

I want a for loop that performs the following operation

iterates on the first element of data2 while iterating over the entire elements of data1

Hope you guys can understand my question and looking forward to your amazing talent

Thank you

4

2 回答 2

2

cellfun您可以根据要使用的内容使用嵌套,data2{ii}并且data1{jj}...

res = cellfun( @( d1 ) cellfun( @( d2 ) myfun( d1, d2 ), data2, 'uni', 0 ), data1, 'uni', 0 );
于 2013-06-11T20:34:42.680 回答
1
data1 = {'x','y','z', 'xyz','yxz'};
data2 = {'b','c','a'};

for k = data2
    for m = data1
        [k{1} m{1}] % Print or use them
    end
end

where kandm1x1元胞数组,您可以使用k{1}or访问其中的字符串k{:}(所有元素现在只有 1)。

于 2013-06-11T20:03:24.660 回答