Average numbers in array

1 view (last 30 days)
Krasimir Terziev
Krasimir Terziev on 4 Aug 2021
Hello,
I've got an array with 65926x2 values. I try to make average when the 1st column got numer of 600 and write in the a new array as 1st cell. Then i want a next average till the numer of 1st column is 1200. What i mean is the time_space_average=[0:600:604800];
So at the end i want to have an array with 1009x1 elements. i will put excel table and picture of the data arrays!
Thanks in advance!

Answers (1)

KSSV
KSSV on 4 Aug 2021
You may proceed some like this shown below:
T = readtable('C:\Users\KSSV\Downloads\1.xlsx') ;
x = T.(1) ; y = T.(2) ;
idx = 0:600:604800;
[c,ia] = ismember(idx,x) ;
n = length(ia);
iwant = zeros(n-1,2) ;
for i = 1:n-1
iwant(i,:) = [idx(i) mean(y(i:i+1))] ;
end
  1 Comment
Krasimir Terziev
Krasimir Terziev on 4 Aug 2021
Hello,
Thanks for the fast answer!
I've got a different answers from that code.
What i mean is 1st.
i change this -> x = T.(1) ; y = T.(2) ; to this -> x = T(:,1); y = T(:,2);
so after that change, the code worked, but
the answer of "iwant" is from 0 to 604200 (not to 604800) - > it can be from 600 ( because average of one number at the zero is the same number) till 604800 including.
and the last one:
When i make average of the numbers in excel table -> there is not equal between the iwant 2nd column = 600 - 233.637405484499 and the table 600 - 233.790024856455.
i will put the same table with 2 average calculations, so the logic have to be the same.
If i miss somethink, just tell me :) im newbie at coding
i will wait for ur respon.
Thanks again!

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!