43 views (last 30 days)

How can I create e distribution of the spread for the data below. I want to have in the same figure 5 distributions respresenting

the spread of the data from its mean in each zone.The columns contain the daily prices for 5 different zones.

My purpose is to check if there are significant differences in the prices between zones. How can I get a similar figure like the one below where the red line is the mean and the blue space showing the data below and above the mean and also the standard deviation of the data. x-axis all the zones and in y-axis the price values.

I have tried to use the following code but it is not fulfilling my purpose. Anyone can help me ...

x1=Data(:,1); x2=Data(:,2); x3=Data(:,3); x4=Data(:,4); x5=Data(:,5);

z1=(x1-mean(x1))/std(x1);

z2=(x2-mean(x2))/std(x2);

z3=(x3-mean(x3))/std(x3);

z4=(x4-mean(x4))/std(x4);

z5=(x5-mean(x5))/std(x5);

pd1=fitdist(z1,'Kernel');

pd2=fitdist(z2,'Kernel');

pd3=fitdist(z3,'Kernel');

pd4=fitdist(z4,'Kernel');

pd5=fitdist(z5,'Kernel');

s=(-2:0.01:2);

y1=pdf(pd1,s);

y2=pdf(pd2,s);

y3=pdf(pd3,s);

y4=pdf(pd4,s)

y5=pdf(pd4,s);;

figure

p=plot(s,y1,'-b',s,y2,'k',s,y3,'-g',s,y4,':r',s,y5,'-m');

title('Empirical kernel')

the cyclist
on 28 Mar 2020

Edited: the cyclist
on 28 Mar 2020

Does using subplots help show your point better?

% Load the data

load Data1.mat

% Convert from table to numeric

Data = table2array(Data1);

% Get the z-score

z = (Data - mean(Data))./std(Data);

% Define the range of s

s = -2:0.01:2;

% For convenience, get the dimensions of these arrays

nr = numel(s);

nc = size(z,2);

% Preallocate memory for the distributions and pdf values. Use a cell array

% for pd.

pd = cell(nc,1);

y = zeros(nr,nc);

% For each column of z, fit the distribution and get the pdf

for nd = 1:nc

pd{nd} = fitdist(z(:,nd),'Kernel');

y(:,nd) = pdf(pd{nd},s);

end

% Plot in subplots

figure

for nd = 1:nc

subplot(nc,1,nd), plot(s,y(:,nd))

end

If not, can you please explain more specifically what you need?

the cyclist
on 28 Mar 2020

Are you looking to perform some kind of statistical test?

One possibility would be to use the two-sample Kolmogorov-Smirnov test, which is a non-parametric hypothesis test.

the cyclist
on 28 Mar 2020

Opportunities for recent engineering grads.

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/513573-how-to-create-a-plot-of-the-spread-of-the-data#comment_816907

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/513573-how-to-create-a-plot-of-the-spread-of-the-data#comment_816907

Sign in to comment.