Hi, I want to write a code that locates the nth value of matrix x= [2,4,6,8,10,12,14,16,18,20] where n is [1:10]. How could I write that?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I want to write a code that locates the nth value of matrix x= [2,4,6,8,10,12,14,16,18,20] where n is [1:10]. How could I write that?
댓글 수: 0
채택된 답변
Atsushi Ueno
2021년 4월 13일
>> x= [2,4,6,8,10,12,14,16,18,20];
>> x(1:10)
ans =
2 4 6 8 10 12 14 16 18 20
>> n=[1:10];
>> x(n)
ans =
2 4 6 8 10 12 14 16 18 20
댓글 수: 0
추가 답변 (1개)
Steven Lord
2021년 4월 13일
That's basic linear indexing. See the "Indexing with a Single Index" section on this documentation page for more information.
x = 2:2:20
n = 1:5
y = x(n)
z = x(3:8)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!