Although now I'm doing this work manually by my hand if there is any chance to know I want to ask is there any way to do this using for loop?
I want to polyfit two by two based on a rule and know slope and y-intercept for each one that runs.
I have a table that describes the name of a couple of station names that should be used in polyfit together. on the other hand, I have a cell including monthly tables for these stations data.
I wonder if any way available to do this like in the code below automatically: (In the table that describes the name of couple station name that should be used in polyfit together there is Ahvaz and Ramhormoz is beside each other)
%calculate P for January (thanks to Adam Danz)
Ahvaz_Jan = getfield(finalStations,'Ahvaz_Jan'); Ramhormoz_Jan = getfield(finalStations,'Ramhormoz_Jan');nanIdx = isnan(Ahvaz_Jan.tmax_m) | isnan(Ramhormoz_Jan.tmax_m);P = polyfit(Ahvaz_Jan.tmax_m(~nanIdx), Ramhormoz_Jan.tmax_m(~nanIdx), 1); % January P (slope and Y intercept)
% calculate P for Feburary
Ahvaz_Feb = getfield(finalStations,'Ahvaz_Feb'); Ramhormoz_Feb = getfield(finalStations,'Ramhormoz_Feb');nanIdx = isnan(Ahvaz_Feb.tmax_m) | isnan(Ramhormoz_Feb.tmax_m);P = polyfit(Ahvaz_Feb.tmax_m(~nanIdx), Ramhormoz_Feb.tmax_m(~nanIdx), 1); % Feburary P (slope and Y intercept)
% For March ...
% ...For December
% looking for next two stations name from table_of_couple_stations.xlsx and do above steps for them
and then looking at the table that describes the name of a couple of station names that should be used in polyfit together and find the next couple and do this for it, and repeat this process until the end, and gives me a table of all P with corresponding stations name.
I don't know if this could be done in Matlab but if there is any way it's a fabulous moment for me.
Best Answer