필터 지우기
필터 지우기

How to find the product of only some of the elements in a vector or matrix in MATLAB

조회 수: 6 (최근 30일)
I need to find the product of some of the elements in a vector. For example from element 120 to element 160. I can only find information about how to find the product of all the elements in a vector (or all the elements in a vector or column of a matrix), this is what the prod command does. How do i find the product of only some of the elements in a vector?

채택된 답변

Jonas
Jonas 2022년 5월 4일
are you looking for
prod(yourVector(120:160))
  댓글 수: 2
Carl Kier
Carl Kier 2022년 5월 4일
Well yes. I did not know that was an option as it is not talked about explicitly in the prod page. Thank you.
Steven Lord
Steven Lord 2022년 5월 4일
The 120:160 piece isn't specifically related to the prod command.
yourVector(120:160) is an indexing operation. See this other documentation page for more information about indexing beyond what's in that Get Started documentation.
Then the whole command calls the prod function on the results of that indexing operation. So it's chaining together multiple operations.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by