필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

what exactly this Logical indexing refering to?

조회 수: 1 (최근 30일)
Mohamed Ahmed
Mohamed Ahmed 2016년 8월 3일
마감: MATLAB Answer Bot 2021년 8월 20일
I tried this example
C = {'one', 'two', 'three'; 1, 2, 3}
when i do those commands
>> x=logical([0;0]);
nums = [C{x,:}]
The output is: nums =[]
similarly when
>> x=logical([0;1]);
nums = [C{x,:}
The o/p is: 1 2 3
>> x=logical([1;0]);
nums = [C{x,:}]
The o/p is: nums= onetwothree
>> x=logical([1;1]);
>> nums = [C{x,:}]
The o/p is: nums= onetwothree
what i want to know, what exactly does this function nums = [C{x,:}]do to return this values.
I knew that if i put x=scalar value, it will return the row if this scalar number.
but in my case, i don't know what this function nums = [C{x,:}]do that it returned the values illustrated above.

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2016년 8월 3일
Please look at the "Using Logicals in Array Indexing" part of this "Matrix Indexing"
web(fullfile(docroot, 'matlab/math/matrix-indexing.html'))

Thorsten
Thorsten 2016년 8월 3일
편집: Thorsten 2016년 8월 3일
When you ask for [C{logical([1 1]),:}] which is the same as [C{:,:}] you ask Matlab to combine variables of unlike classes, namely double and char. In this case Matlab converts the resulting array to char, as detailed in http://de.mathworks.com/help/matlab/matlab_prog/valid-combinations-of-unlike-classes.html
char(2) and char(3) result in a space on my machine, you the result you get is
onetwo three

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by