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 Kommentare

Birdman
Birdman am 12 Jan. 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]

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Stephen23
Stephen23 am 12 Jan. 2018
Bearbeitet: Stephen23 am 12 Jan. 2018

1 Stimme

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 Kommentar

marco lopes
marco lopes am 12 Jan. 2018
Bearbeitet: Stephen23 am 12 Jan. 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]

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by