I need some help with a function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Vonderhaar
el 18 de Jul. de 2021
Comentada: Daniel Vonderhaar
el 18 de Jul. de 2021
Hi!
So I am trying to make a function named lowerRightQuarter that takes one argument, a matrix, with an even number of rows and columns. The function then returns the lower right quarter of the input matrix as a new matrix. This is what I have so far.
function n=lowerRightQuarter(A)
n=A(2 : 2 : end, 2 : 2 : end);
end
My Page looks like this
%% Lower Right Quarter
A=[1 2 3 4;
5 6 7 8;
0 1 2 3;
4 5 6 7];
lowerRightQuarter(A)
So the out put should be
2 3
6 7
Then after that if I run it again with 2 3; 6 7. I should just get 7.
Please help!.If you would please get me your answer ASAP that would be great!
Thank you so much
Daniel
0 comentarios
Respuesta aceptada
Image Analyst
el 18 de Jul. de 2021
You're getting every other row. Try this:
function n = lowerRightQuarter(A)
[rows, columns] = size(A);
middleRow = rows / 2 + 1;
middleCol = columns / 2 + 1;
n = A(middleRow : end, middleCol : end);
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements 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!