You can create a loop to iterate over the elements of the vector and add the terms that match the condition c(ii) == 3
. The code below demonstrates how to do this:
main.m115 chars11 lines
In this example, we initialize the vector c
, the variable sum
to 0, and then iterate over the elements of c
using a for loop. For each element of c
, we check if the condition c(ii) == 3
is true. If it is, we add the current element to sum
. Finally, we display the value of sum
.
gistlibby LogSnag