MATLAB Answers

How to create a plot of the spread of the data

43 views (last 30 days)
gjashta on 28 Mar 2020
Edited: gjashta on 30 Mar 2020
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);
title('Empirical kernel')

  1 Comment

the cyclist
the cyclist on 28 Mar 2020
FYI, I used the CODE button to format your code.

Sign in to comment.

Accepted Answer

the cyclist
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);
% Plot in subplots
for nd = 1:nc
subplot(nc,1,nd), plot(s,y(:,nd))
If not, can you please explain more specifically what you need?


Show 1 older comment
the cyclist
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.
gjashta on 28 Mar 2020
Do you think the two-sample Kolmogorov-Smirnov test will help me, because I just want a way how to show the variability as a distribution, I have also used boxplot, histogram, and histcounts for each zone but as the data vary from 13-15 I got very few bins.
the cyclist
the cyclist on 28 Mar 2020
Can you be more specific in what you mean by "show the variability"? To me, the subplots of the distributions give very complete information, so I don't understand what the problem is. Could you draw a picture by hand? Or are you trying to calculate a number?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!