Borrar filtros
Borrar filtros

Creating a matrix which has particular order of element ?

1 visualización (últimos 30 días)
P K
P K el 21 de En. de 2019
Editada: Andrei Bobrov el 21 de En. de 2019
Hello all,
I have to obtain a matrix. The matrix looks like
A=[1 0 0 0 0 0;0 2 0 0 0 0;3 0 4 0 0 0;0 5 0 6 0 0;7 0 8 0 9 0;0 10 0 11 0 12];
% There is a sequence.Odd row and even row.
% ODD ROW- Element stasts from first column
% EVEN ROW- Element start from second coloumn
% Each element is +1 to the previous element.
I can do this with "FOR-LOOP". But is there some effiecient way to do this.
Thanks you !

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 21 de En. de 2019
Editada: Andrei Bobrov el 21 de En. de 2019
m = 6;
n = 6;
lo = triu(~rem((1:n)' + (1:m),2));
out = int64(lo);
out(lo) = 1:nnz(lo);
out = out';
with kron
m = 7;
n = 6;
out = triu(kron(ones(ceil(n/2),ceil(m/2)),[1,0;0,1]));
out = out(1:n,1:m);
out(out~=0) = 1:nnz(out);
out = out';

Más respuestas (1)

Kevin Phung
Kevin Phung el 21 de En. de 2019
Can you be more clear in what you are trying to do? Is this pattern supposed to go on? Or is this matrix A that you have provided exactly what you need, and you are looking for a way to programmatically create it rather than typing it out .

Categorías

Más información sobre Mathematics and Optimization 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