채택된 답변

Stephan
Stephan 2019년 3월 1일

0 개 추천

Hi,
you do linear indexing which lets Matlab reshape A. To avoid this use:
A(:,1)=[]
Best regards
Stephan

댓글 수: 3

zhenyu zeng
zhenyu zeng 2019년 3월 1일
편집: zhenyu zeng 2019년 3월 1일
So, in this way, any A will be come a linear data line, not a matrix. It is so terrible. But can you tell what its advantage is?
Stephan
Stephan 2019년 3월 1일
There are 2 ways of indexing in Matlab. Depending on what you want to do the one maybe better or the other. Knowing both and how they behave lets you make the right decision. I think having 2 possibilities is the advantage.
If you delete elements using linear indices, if MATLAB didn't reshape the resulting elements into a vector you could end up with an array with different numbers of elements in each row or column. That's not allowed. Arrays in MATLAB must be "rectangular".
thisWillNotWork = [1 2; 3]
In your particular case the elements remaining after the deletion would still be arranged in a rectangle. But in general they wouldn't. Ideally you shouldn't need to check after performing that deletion operation what shape the result is.
In fact, even if you don't delete any elements at all we reshape the result. You tried to delete elements, so we put your data in the shape of a vector.
A = magic(4);
A([]) = [];
size(A) % [1 16]

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

추가 답변 (1개)

TADA
TADA 2019년 3월 1일

0 개 추천

you accessed a 2d matrix with linear indexing,
If you want to retain the dimentions of your matrix use subscripts instead:
A(:,1) = []
A =
0 0
2 2

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

질문:

2019년 3월 1일

댓글:

2019년 3월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by