You can calculate the positive elements in a MATLAB array by using logical indexing.
Here is an example code snippet that demonstrates how to do that:
main.m210 chars5 lines
The first line creates an array for demonstration purposes. The second line uses logical indexing to select only the positive elements and store them in a new array called positive_elems.
The third line calculates the number of positive elements in positive_elems using the length() function, and stores the result in a new variable called num_positive_elems. The fourth line displays the result using the disp() function.
gistlibby LogSnag