I have a giant data array where in every row I want to extract specific columns and then average the numbers I extract. This is my code:
for i=1:1000
temp=data(i,:);
index_data=temp([1,10,11,12,19]); %columns I want to extract
data_final(i,1)=mean(index_data(~isnan(index_data)));
end
I get an error on the first iteration. The array that is extracted is
[NaN NaN NaN NaN 15.64]
And what I get when I type index_data(~isnan(index_data)) is 15.64, what I'd expect. However, I get an error of
??? Subscript indices must either be real positive integers or logicals.
Error in ==> mean(index_data(~isnan(index_data)))
Calling this from the command line yields the same error. However, if I try with the covariance function (cov) I don't the get the error. This seems really weird to me!
Thanks for your help!