Matrix with numerical sequence

Hi!
i am creating a matrix (n,m), which are the input values. the matrix needs to be like this:
[1 4 2 .... 4 2 4 1;
4 16 8 ....16 8 16 4;
2 8 4 ... 8 4 8 2;
.... .....;
4 16 8 ...16 8 16 4;
2 8 4 .... 8 4 8 2;
4 16 8 ....16 8 16 4;
1 4 2 .....4 2 4 1]
how do i code this in matlab?

2 comentarios

Birdman
Birdman el 12 de En. de 2018
The pattern is not clear to me. Can you be more specific?
let me try to explain better, sry for bad english i got a matriz which is A= [1 4 1; 4 16 4; 1 4 1] and that matrix will add like this M =[1, 4, 1+1, 4, 1; 4, 16, 4+4, 16, 4 1+1, 4+4, 1*4', 4+4 1+1; 4, 16, 4+4, 16, 4 1, 4, 1+1, 4, 1], '=1+1+1+1 #which basicaly is the sum of the last column of A with the 1st of A, and the sum of the last line of A with the first line A;
*This repeated in a way i get a matriz with (i,j), always impar's.
*Resume: i want to know how to add A, in a a way that "A(m,n)+A(p,k)", gives, for example, a matriz that is (3,5) which adds the A(m,3) with A(p,1), and keeps the rest
#example 2: A(m,n)+A(p,k) gives a (7,5) that becomes
[1 4 2 4 1; 4 16 8 16 4; 2 8 4 8 2; 4 16 8 16 4;
2 8 4 8 2; 4 16 8 16 4; 1 4 2 4 1]

Iniciar sesión para comentar.

 Respuesta aceptada

Stephen23
Stephen23 el 12 de En. de 2018
Editada: Stephen23 el 12 de En. de 2018
N = 7; % must be odd
M = ones(N)*16;
M(1:2:N,:) = 4;
M(2:2:N*N) = 8;
M(:,[1,N]) = M(:,[1,N])/2;
M([1,N],:) = M([1,N],:)/2;
giving:
M =
1 4 2 4 2 4 1
4 16 8 16 8 16 4
2 8 4 8 4 8 2
4 16 8 16 8 16 4
2 8 4 8 4 8 2
4 16 8 16 8 16 4
1 4 2 4 2 4 1

1 comentario

marco lopes
marco lopes el 12 de En. de 2018
Editada: Stephen23 el 12 de En. de 2018
let me try to explain better, sry for bad english i got a matriz which is
A = [1 4 1;
4 16 4;
1 4 1]
and that matrix will add like this
M =[1, 4, 1+1, 4, 1;
4, 16, 4+4, 16, 4
1+1, 4+4, 1*4', 4+4 1+1;
4, 16, 4+4, 16, 4
1, 4, 1+1, 4, 1], '=1+1+1+1
which basicaly is the sum of the last column of A with the 1st of A, and the sum of the last line of A with the first line A;
This repeated in a way i get a matriz with (i,j), always impar's.
i want to know how to add A, in a a way that "A(m,n)+A(p,k)", gives, for example, a matriz that is (3,5) which adds the A(m,3) with A(p,1), and keeps the rest
example 2: A(m,n)+A(p,k) gives a (7,5) that becomes
[1 4 2 4 1;
4 16 8 16 4;
2 8 4 8 2;
4 16 8 16 4;
2 8 4 8 2;
4 16 8 16 4;
1 4 2 4 1]

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Preguntada:

el 12 de En. de 2018

Editada:

el 12 de En. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by