how can i generate a matrix as shown [1 1 1 1 1 1 1 1; 1 1 1 1 2 2 2 2; 1 1 2 2 3 3 4 4; 1 2 3 4 5 6 7 8]

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 13 de Jul. de 2015
Editada: Azzi Abdelmalek el 13 de Jul. de 2015

0 votos

m=4;
n=2^(m-1);
b=zeros(m,n);
for k=0:m-1
a=1:2^k;
b(k+1,:)=reshape(repmat(a,n/numel(a),1),1,[]);
end
b
Or
m=4
n=2^(m-1)
b=cell2mat(arrayfun(@(x) reshape(repmat(1:2^x,n/numel(1:2^x),1),1,[]),(0:m-1)','un',0))

2 comentarios

ali sedeek
ali sedeek el 13 de Jul. de 2015
thanks
Image Analyst
Image Analyst el 13 de Jul. de 2015
What was wrong with
m = [1 1 1 1 1 1 1 1; 1 1 1 1 2 2 2 2; 1 1 2 2 3 3 4 4; 1 2 3 4 5 6 7 8];
It generates exactly what you asked for without assuming anything that you did not state. If you have some pattern, or generality in terms of size of dimensions, then you should have stated what it is.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 13 de Jul. de 2015

Comentada:

el 13 de Jul. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by