I want to fill NaNs in a certain column of tables in C.mat, using a linear regression equation with regards to the information that stored in stationList.mat and other C.mat tables. In fact, I require to fill NaN rows in the tmax_m column (at C.mat tables which I attached it) of each station, using a similar row in other tables in C that closest_station (second column of stationList.mat) visualized it and corresponding slope and y-intercept in a similar month (that presents in stationList.mat).
For example:
in C{1, 1}, which station_name is Abadan, All NaN rows should be filled using similar row in Bandare-E-Mahshahr (as it displayed in stationList -second column, first row-) and this linear regression coefficients:
rowIdx = strcmp(stationList.station_name,'Abadan') & strcmp(stationList.closest_station,'Bandar-E-Mahshahr');coeffs = stationList.Feb(rowIdx,:); %output is m (slope) and intercept respectively
NaN in Ahvaz = slope x similar row in Bandar-E-Mahshahr + intercept
I saw that this item can be done manually that I achieve linear regression coefficients using above-mentioned code then look at a corresponding row in nearest_station and use NaN in Ahvaz = slope x similar row in Bandar-E-Mahshahr + intercept to manually fill NaN, but as you know this process is so many time-consuming
I want to run this process for all C.mat tables. I was searching for a solution for about 3 hours until now but I can't do it. So any help, any advice is appreciated.
Thank you in advance.
Best Answer