i'm developing a program in octave that i will explain as i put the code. So i have this matrix in a file called matprec.m:
function [res1] = matprec()
res1 = [
1,2001,1,2,0.00;
1,2001,1,5,5.33;
2,2001,1,5,4.57;
3,2001,1,5,5.33;
4,2001,1,5,5.59;
5,2001,1,5,4.32;
2,2001,1,13,0.00;
3,2001,1,13,0.00;
4,2001,1,13,0.00;
3,2001,1,30,30.73;
2,2001,2,1,1.02;
3,2001,2,1,1.52;
4,2001,2,1,1.78;
5,2001,2,1,1.27;
1,2001,2,2,1.78;
2,2001,2,2,1.27;
3,2001,2,2,1.78;
4,2001,2,2,2.03;
5,2001,2,2,1.78;
1,2001,3,4,18.03;
3,2001,3,4,15.75;
5,2001,3,4,17.53;
1,2001,3,5,13.46;
2,2001,3,5,12.19;
3,2001,3,5,11.94;
4,2001,3,5,9.65;
5,2001,3,5,10.92;
2,2001,4,30,0.00;
4,2001,4,30,0.00];
format short g
return
endfunction
So in this matrix the first column is just the station where we measure the amount of precipitation, the second is the year, the third is the month, the fourth is the day and the fifth is the value of precipitation. And what i want to do in another file is call this matrix and do the following calculus, in the month 1 i want do the average on all the days for example:
in month 1 day 5 i have 5 values 5.33, 4.57, 5.33, 5.59, 4.32, so i would do
(5.33 + 4.57 + 5.33 + 5.59 + 4.32)/5 = 5.028
And i want to do that for all the days and when i have all the days i would add them all to know the amount of precipitation in that month, and do that for all the 4 months.
That's how the program should function and i already accomplished that with this piece of code:
Result = matprec();
month1Indices = Result(:,3) == 1;
month1Rows = Result(month1Indices, :);
day5Indices = month1Rows(:,4) == 5;
day5Rows = month1Rows(day5Indices , :);
mean(day5Rows(:,5));
Result2 = matprec();
month1Indices2 = Result2(:,3) == 1;
month1Rows2 = Result2(month1Indices2, :);
day5Indices2 = month1Rows2(:,4) == 30;
day5Rows2 = month1Rows2(day5Indices2 , :);
mean(day5Rows2(:,5));
mes1 = mean(day5Rows(:,5)) + mean(day5Rows2(:,5));
lol = [mes1, mes2, mes3, 0, 0, 0, 0, 0, 0, 0, 0, 0];
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
plot(x,lol);
But that only work for the first month, so i'm trying to do a while loop to do that for all the month's and all the day's and plot it, i have this but it just continue forever:
a = 1
b = 1
while (a <= 4 && b <= 30)
Result = matprec();
month1Indices = Result(:,3) == a;
month1Rows = Result(month1Indices, :);
day5Indices = month1Rows(:,4) == b;
day5Rows = month1Rows(day5Indices , :);
mean(day5Rows(:,5))
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
plot(x,mean(day5Rows(:,5)));
endwhile
Sory i know it's a bit long, but i need to explain it, thanks.