Difficulty to get the results by using repmat function

Hello everyone, I am working on climate data and I have a matrix size of 12x361, (where the 12 represents the months and 361 represents the columns).
Now i want to repeat the factor values of each corresponding months (Jan-Dec) of the 361 stations into 30years (say 1931 to 1961) on the daily wise.
For example i have "Jan" month factor value of 0.778, "Feb" month is 0.65, "Mar" is 0.56 ....and Dec is 0.69, Now i want to repeat the each factor value
of the particular months into days and into 30years for all the 361 stations and the data should be arranged serially (say Jan-1931, Feb-1931... Dec-1960)
I have tried the code below shown for your reference and required your valuable suggestions to proceed further.
load BCC_CF_Mul_pr_1961.mat
b=BCC_CF_Mul_pr_1961(:,1:361); %12rows of factor values for all the 361 stations
% Inserts Year and Months
x=bsxfun(@(Month,Year) datenum(Year,Month,1),(1:12).',1931:1960);
x=x(:);
d=datevec(x);
d=d(:,1:2);
%inserting number of days in a month of the year
a1=eomday(d(:,1),d(:,2));
%Repeat the evry month of the factor values to the days caculated from the previous step
a2=repmat(b(1),a1(1),1); %this line repeats the values only for that month
Kindly help me to proceed further
Thank you

 Respuesta aceptada

Jan
Jan el 11 de Jun. de 2019
I'm not sure, what you are asking for. With some guessing:
a1 = eomday(d(:,1),d(:,2));
index = repelem((1:size(b, 1)).', a1);
a2 = b1(index, :);

6 comentarios

Hello Sir, thank you for earliest reply
I tried your code but facing error "Error using repelem, In repelem(v, N), N must be a scalar or a vector of length equal to v.
find the below attached .mat file for your reference. In that, 12 factor values for 361 stations (means size of matrix is 12x361) corresponsing to the months, I want to repeat the "jan", "Feb"... "Dec" months factors into days for each individual years
Year/Month/Day Factor
1931/01/01 0.745
" "
1931/01/31 0.745
1931/02/01 0.65
" "
1931/02/28 0.65
"
"
1960/12/01 0.45
" "
1960/12/31 0.45
similarly the same factor values of each months (Jan-Dec) need to be repeated to all the 30years (1931-1960) dailywise for all the 361 stations. I have attached the result file sample showing data arrangement, i want to arrange it like this type but i followed the different method and i want to reduce the script lines
Thank you
You are welcom. Unfortunately I do not really understand, what you need. What does "i followed the different method and i want to reduce the script lines" mean?
Do you see how repelem works? I assume it will solve your problem.
Maybe you want to repeat the index values of b also?
v = repmat((1:12).', 30, 1); % For the 30 years from 1931:1960
index = repelem(v, a1);
This is only an idea, not a solution. Try to let it inspire you.
Thank you sir, I'm sorry for the explanation
> What does "i followed the different method and i want to reduce the script lines" mean?
means previously i used the functions (eomday and repmat) separtely for all the 361stations to repeat the particular factor values in to 30years because of MATLAB 2014version. By following your suggestion now i used "repelem" function and i got the above error and the same i commented.
>Do you see how repelem works? I assume it will solve your problem.
Yes sir, i tried yesterday and i got the results and i have made the changes
>Maybe you want to repeat the index values of b also?
Yes true sir i i did the same and i got the required format and attached the same below for further suggestions
load BCC_CF_Mul_pr_1961.mat
CF_Values=BCC_CF_Mul_pr_1961(:,1:361); %12rows of factor values for all the 361 stations
%%%%%%%% Repeats the factors for all the 30years of the month
CF_Values=repmat(CF_Values,30,1);
%%%%%%%%% Inserts Years and Months
x=bsxfun(@(Month,Year) datenum(Year,Month,1),(1:12).',1931:1960);
x=x(:);
Year_Month=datevec(x);
Year_Month=Year_Month(:,1:2);
%%%%%%%%% Calculates number of days in the months for all 30years
BCC_CF_Mul_pr_1931_60 = eomday(Year_Month(:,1),Year_Month(:,2 ));
%%%%%%%%% repeat the factor values of the each individual months into the days of that %%%particular year
BCC_CF_Mul_pr_1961_90 = repelem(CF_Values(:,1:361),BCC_CF_Mul_pr_1961_90(1:360),1);
save('BCC_CF_Mul_pr_1961_90.mat','BCC_CF_Mul_pr_1961_90');
clear
clc
Thank you sir and i have some doubts on the other codes, can i ask you?
Jan
Jan el 13 de Jun. de 2019
Editada: Jan el 13 de Jun. de 2019
Of course you can ask any Matlab related questions in this forum. Simply open a new thread.
Here in Europe it is unusual to call other persons "sir". So please do not bother, if other users or me do not use this epxression. It is not meant impolite.
Thank you, below code was refered to carry out timeseries trend to detect the increase or decrease in the precipitation. The size of the data was arranged by annualy for 361 climate stations, Acordingly i have arranged my data annualy (arranged in rows) and tried to calculate the trend and i got the results for the particular station (or single station arranged in column wise), but the problem is i have 361 climate station data for the 116 annual years, how to use this code to get the value "tau" for all the 361station. Previously i used XLStat trail version to calculate the "tau" value, in that i have selected all the 361 station data and got the results for all the individula station how to do the same in the matlab using the below code
I have made some modfication in the code written by the author to calculate the tau and also attached the data for your reference.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Simone Fatichi -- simonef@dicea.unifi.it
% Copyright 2009
% $Date: 2009/10/03 $
load Annual_IMD_Pr_1901_2016.mat
A=Annual_IMD_Pr_1901_2016(:,4); % select the required station data
V=reshape(A,length(A),1);
alpha = 0.05/2;
n=length(V);
i=0; j=0; S=0;
for i=1:n-1
for j= i+1:n
S= S + sign(V(j)-V(i));
end
end
VarS=(n*(n-1)*(2*n+5))/18;
StdS=sqrt(VarS);
%%%% Note: ties are not considered
if S >= 0
Z=((S-1)/StdS)*(S~=0);
else
Z=(S+1)/StdS;
end
p_value=(1-normcdf(abs(Z))); %% one-tailed test
pz=norminv(1-alpha);
H=abs(Z)>pz;
D=n*(n-1)/2;
tau=S/D; %Trend value for the particular station
return
Jan
Jan el 14 de Jun. de 2019
@Nataraja M: As far as I can see, this is a new question. Then, as said already, open a new thread to ask it. This is better than attaching a new question as a comment in another thread.
"how to do the same in the matlab using the below code" - this is hard to answer, because I do not really understand what you have done with which other software. Please post, what the inputs are and what you need as output.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Climate Science and Analysis en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 11 de Jun. de 2019

Comentada:

Jan
el 14 de Jun. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by