Search code examples
scilab

Scilab, calculate average of part of vector (Matrix column)


matrix data with two columns have time (1st column) and angle (2nd column) information stored. I need to calculate the average of the angle information between 5000 and 13000. Problem, 5000 and 13000 doesn't exist as exact values in the 1st column.

I tried to find the index in the x-value vector for given points but I fail always on the problem not having the exact search value in the matrix 1st column. Thanks!

enter image description here


Solution

  • Use boolean indexing, e.g.

    k = data(:,1) >= 5000 & data(:,1) <= 13000 
    avg = mean(data(k,:))