Reputation: 15
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
Upvotes: 0
Views: 108
Reputation: 114786
You can use nested cellfun
depending on what you want to do with data2{ii}
and data1{jj}
...
res = cellfun( @( d1 ) cellfun( @( d2 ) myfun( d1, d2 ), data2, 'uni', 0 ), data1, 'uni', 0 );
Upvotes: 2
Reputation: 1860
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 k
and m
are 1x1
cell arrays, and you can access the string inside them with k{1}
or k{:}
(all the elements which is only 1 now).
Upvotes: 1