How to find the product of only some of the elements in a vector or matrix in MATLAB
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Carl Kier
am 4 Mai 2022
Kommentiert: Steven Lord
am 4 Mai 2022
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?
0 Kommentare
Akzeptierte Antwort
Jonas
am 4 Mai 2022
are you looking for
prod(yourVector(120:160))
2 Kommentare
Steven Lord
am 4 Mai 2022
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!