필터 지우기
필터 지우기

hi i started the matlab onramp course and im stuck on this further practice question i wld appreciate if anyone cld help me or even give an hint

조회 수: 18 (최근 30일)
  댓글 수: 3
Image Analyst
Image Analyst 2024년 8월 22일
That is not a question. It's just giving you information. For a demo of that, see the Answer below (scroll down) or show us the actual question.

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

채택된 답변

Steven Lord
Steven Lord 2024년 8월 22일
As Image Analyst stated, it's an informational message not a question. Its intent is to let you know that the indices you use to index into an array in MATLAB need not refer to a contiguous section of the array. [They can, but they're not required to.]
x = (1:10).^2 % original array into which you want to index
x = 1x10
1 4 9 16 25 36 49 64 81 100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
contiguous = x([4 5 6]) % a section of x from the middle
contiguous = 1x3
16 25 36
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
You can skip elements.
skip = x(1:2:end) % get every other element of x
skip = 1x5
1 9 25 49 81
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
You can repeat elements.
repeated = x([3 5 5 7]) % 25 appears twice in the output
repeated = 1x4
9 25 25 49
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
You can specify indices that aren't sorted.
unsorted = x([1 4 7 10 2:3:8 3 6 9]) % "shuffle" the elements
unsorted = 1x10
1 16 49 100 4 25 64 9 36 81
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
In this last section I used the "skip" pattern as part of generating the unsorted list. I could have done that slightly more compactly by using it for all three sections.
unsorted2 = x([1:3:10 2:3:8 3:3:9]) % "shuffle" the elements
unsorted = 1x10
1 16 49 100 4 25 64 9 36 81
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2024년 8월 22일
density=10:10:100
density = 1x10
10 20 30 40 50 60 70 80 90 100
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
index=[1 3 6]
index = 1x3
1 3 6
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
SelectedDensityValue=density(index)
SelectedDensityValue = 1x3
10 30 60
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by