Borrar filtros
Borrar filtros

i want to get top right n x n matrix out of Nx N, I programmed it in following way but i got answer two times. so what is my mistake?

3 visualizaciones (últimos 30 días)
a = top_right(N,n)
[j , k] = size(N);
a = N([1:1:j-(j-n) , 1:1:k-(k-n)],1:n);
end

Respuestas (1)

James Tursa
James Tursa el 19 de Nov. de 2018
Editada: James Tursa el 19 de Nov. de 2018
For "top right corner," the column indexing should not start at 1. E.g.,
a = N(1:n,end-n+1:end); % <-- Back off from end instead of starting from 1
But you might want to add code to cover the cases where the dimensions of N are smaller than n.

Categorías

Más información sobre Get Started with 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