vectorized code to make square matrix from nxm matrix

Hey so the problem I have is that I am supposed to make a square matrix from an mxn matrix (2x4 or 4x9 etc). Basically what the code will do is delete the first row or column until it becomes a square matrix. The catch is that i cannot use if statements.. which makes this harder.
My idea before i saw that i couldnt use if statements was check if r = c then eliminate rows or columns depending on which one is bigger using A(:,c-r)=[]; if that would work.
I erased my code with the if statement after i read that part ( I got overzealous and didnt finish reading the question). Does anyone have any tips to help me?

 Respuesta aceptada

min(size(A))

3 comentarios

I get that that would give me the smallest dimension of the matrix, but how would I use that to my benefit?
n=min(size(A))
A(1:n,1:n)
Ahh that makes sense. Thank you so much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 16 de Nov. de 2014

Comentada:

el 16 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by