Get all unique combinations from cell array for use as functional arguments
Afficher commentaires plus anciens
Hello,
I have data stored in a n x n cell array. For example:
data = {rand(1000,1) rand(1000,1); rand(1000,1) rand(1000,1)};
I want to compute the mean squared error between all possible unique cell combinations. In this case, if computed manually, they would be the following:
immse(data{1,1}, data{1,2});
immse(data{1,1}, data{2,1});
immse(data{1,1}, data{2,2});
immse(data{1,2}, data{2,1});
immse(data{1,2}, data{2,2});
immse(data{2,1}, data{2,2});
I will work with larger cell arrays than in this example (e.g., 10 x 10 instead of 2 x 2). In those cases, I do not want to type out the combinations manually.
I am therefore trying to find a way / a function to automatize this process. Can anyone help?
Thanks a lot in advance.
Réponse acceptée
Plus de réponses (1)
This can be achieved by 2 loops using linear indexing:
for i1 = 1:numel(data)
for i2 = 1:numel(data)
immse(data{i1}, data{i2})
end
end
ind2sub let you get the 2 indices from the single linear index on demand. But 4 loops are possible also:
[s1, s2] = size(data);
for i1 = 1:s1
for i2 = 1:s2
for i3 = 1:s1
for i4 = 1:s2
immse(data{i1, i2}, data{i3, i4})
end
end
end
end
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!