Get all unique combinations from cell array for use as functional arguments

2 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

KSSV
KSSV el 8 de En. de 2021
A 2*2 matrix means there are four elements i.e. four global indices.
idx = 1:4 ;
c = nchoosek(idx,2)
C has the possible combination's indices. You can use those indices to get the required error.

Más respuestas (1)

Jan
Jan el 8 de En. de 2021
Editada: Jan el 8 de En. de 2021
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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by