Borrar filtros
Borrar filtros

print a matrix in a specific sequence

3 visualizaciones (últimos 30 días)
Mahmoud Khadijeh
Mahmoud Khadijeh el 11 de Jun. de 2019
Editada: madhan ravi el 11 de Jun. de 2019
Hello All ,
I want to print a Matrix like this
A=[5
4
3
2
1
0
5
4
3
2
1
0
.
.];
I want numbers from 1 to 5 to be repeated in this form several times

Respuesta aceptada

Chirag Nighut
Chirag Nighut el 11 de Jun. de 2019
You can use the repmat function here
If you have to print the patter N (here 10) times, use the following code:
A = [5 4 3 2 1 0]';
N = 10;
B =repmat(A, N,1)
  2 comentarios
madhan ravi
madhan ravi el 11 de Jun. de 2019
Editada: madhan ravi el 11 de Jun. de 2019
Providing a complete solution to a homework problem is not recommended. Provide hints instead thank you.
Mahmoud Khadijeh
Mahmoud Khadijeh el 11 de Jun. de 2019
Thank's "Chirag Nighut ", that's also works for me.
Regards

Iniciar sesión para comentar.

Más respuestas (1)

Utkarsh Belwal
Utkarsh Belwal el 11 de Jun. de 2019
length = 100 ; % This will produce a 120 length output
A = [] ;
value = 5 ;
for i = 1 : length
A = [A ; value] ;
value = value - 1 ;
if mod(i , 5) == 0
A = [A ; 0] ;
value = 5 ;
end
end
disp(A)
  1 comentario
Mahmoud Khadijeh
Mahmoud Khadijeh el 11 de Jun. de 2019
Thank you very much, yes that's what I want and also repmat works for me

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB 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