필터 지우기
필터 지우기

extracting submatrices from cell

조회 수: 1 (최근 30일)
Daniel
Daniel 2013년 4월 27일
Consider the following bit of code:
X={1, 'a'; 'b', 3.14};
X(2,:)
X{2,:}
It produces the following output:
ans = 'b' [3.1400]
ans = b
ans = 3.1400
Can anyone explain to me the reason for the difference. I would have expected the statement X(2,:) to fail and that X{2,:} would have produced what X(2,:) did, in fact, produce.

채택된 답변

Ahmed A. Selman
Ahmed A. Selman 2013년 4월 27일
Try the same example with:
X={1, 'a'; 'b', 3.14};
K1=X(2,:)
[K21 K22]=X{2,:}
Then use
whos
to see that K1 is a cell, i.e., it only puts part from X into K1, while [K21 K22] is [char double], extracting the contents of the cell into a matrix. The first operation (K1) is another way for cell concatenation.
  댓글 수: 2
Daniel
Daniel 2013년 4월 27일
Thanks for your answer. So X(2,:) is the same as {X{2,:}}. While I can clearly see this is true, I was hoping to see why this is true. How are
( , )
and
{ , }
defined so that I can predict the outcome of these commands.
Ahmed A. Selman
Ahmed A. Selman 2013년 4월 27일
(,) is a portioning, or concatenation process; while
{,} is an extraction, or transformation one .. :)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by