Borrar filtros
Borrar filtros

How to modify a function to make it accept an array of arrays or a cell of arrays?

1 visualización (últimos 30 días)
Hi All,
I found the attached file on internet, this file is a function that gives all the combinations of all elements of the given arrays.
ex1:
>> allcomb([1 2],[3 4])
ans =
1 3
1 4
2 3
2 4
Now, my question is how we can change on this function to make is accept a cell of arrays or an array of arrays.
ex2:
if we have the following code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
close all
for i=1:2
p{i}=[2^i-1 2^(i)];
end
allcomb(p)%This line does not work.
Cell={};
for i =1:max(size(p))
Cell{i}=p{i};
end
allcomb(Cell)%This line does not work.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The lines that have the comment "%This line does not work." do not give the same answer as ex1.
Could you help me please?.
  2 comentarios
Image Analyst
Image Analyst el 13 de Abr. de 2015
If I told you I'm not sure you'd take my advice. I gave you several pieces of advice how to improve this bad code in your other question but I can see you didn't take that advice because you're still using the same code here.
hadi
hadi el 13 de Abr. de 2015
Sorry, but I think you are talking about someone else, this is the first time I post this code here.

Iniciar sesión para comentar.

Respuesta aceptada

hadi
hadi el 13 de Abr. de 2015
This is the correct answer: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
close all
for i=1:2
p{i}=[2^i-1 2^(i)];
end
Cell={};
for i =1:max(size(p))
Cell{i}=p{i};
end
allcomb(Cell{:})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The output:
ans =
1 3
1 4
2 3
2 4

Más respuestas (0)

Categorías

Más información sobre Genomics and Next Generation Sequencing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by