필터 지우기
필터 지우기

vectorized code to make square matrix from nxm matrix

조회 수: 1 (최근 30일)
David Phung
David Phung 2014년 11월 16일
댓글: David Phung 2014년 11월 16일
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?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 16일
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 16일
n=min(size(A))
A(1:n,1:n)
David Phung
David Phung 2014년 11월 16일
Ahh that makes sense. Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by