# Plotting "Continuous" Histograms in Octave/Matlab

• Aug 12th 2010, 01:12 PM
redherring
Plotting "Continuous" Histograms in Octave/Matlab
Hi folks,

I'm in the midst of analyzing a set of data and it involves plotting the distribution of a large number of ions.

I currently am using the hist function in Octave to do so, and it produces graphs along the following lines, give or take bin-size.

Attachment 18532

However, my supervisor does not like this "style" of graph; and wishes to for it to look like the following distribution (not the same data as above!):

Attachment 18533

I was wondering if there was a simple way to do this in Octave, whether its curve fitting to a series of points or something else. Basically, I am in desperate need of a "continuous distribution" graph.

J
• Aug 12th 2010, 01:38 PM
CaptainBlack
Quote:

Originally Posted by redherring
Hi folks,

I'm in the midst of analyzing a set of data and it involves plotting the distribution of a large number of ions.

I currently am using the hist function in Octave to do so, and it produces graphs along the following lines, give or take bin-size.

Attachment 18532

However, my supervisor does not like this "style" of graph; and wishes to for it to look like the following distribution (not the same data as above!):

Attachment 18533

I was wondering if there was a simple way to do this in Octave, whether its curve fitting to a series of points or something else. Basically, I am in desperate need of a "continuous distribution" graph.

J

Google "Kernel Density Estimation" and/or "Kernel Density Estimation octave"

CB
• Aug 12th 2010, 01:44 PM
yeKciM
hmmm... i didn't use "matlab" for a long time but i'm sure that u can plot what your supervisor wants very easy... sorry i forgot the syntax for that, actually i'm not hundred percent sure, so i don't wont to mislead you... cool thing in matlab is "help" function, so u can see exactly how u can do that what you need :D

try that if you have matlab, it's very easy to manipulate with type of plot you need, :D to look very nice you don't have to type more than few lines of code :D
• Aug 12th 2010, 11:29 PM
CaptainBlack
Quote:

Originally Posted by yeKciM
hmmm... i didn't use "matlab" for a long time but i'm sure that u can plot what your supervisor wants very easy... sorry i forgot the syntax for that, actually i'm not hundred percent sure, so i don't wont to mislead you... cool thing in matlab is "help" function, so u can see exactly how u can do that what you need :D

try that if you have matlab, it's very easy to manipulate with type of plot you need, :D to look very nice you don't have to type more than few lines of code :D

I beleive that Matlab has kernel density estimation in one of its tool-boxes. KDE is the only method I know for producing smooth estimates of a density from sample data (that and its a pretty cool method).

As usual the wikipedia KDE article is useful, even pointing to the Matlab function that will do the job.

CB
• Aug 13th 2010, 08:43 AM
yeKciM
although i was more in to "simulik" with matlab i think that this is what u need :D

here is one m-file (that u need to make or u can write this directly in command window)

clear all
close all
clc

t=-5:0.01:5 ;
x=cos(10*pi*t)+sin(2*pi*t);
figure(1)
plot(t,x,'r')
axis([-5 5 -2.5 2.5])
title('x(t)=cos(10 \pi t )+sin (2 \pi t')
xlabel('t')
ylabel('x(t)')
grid on

Attachment 18545

or u can do in multicolor :D like this :D

clear all
close all
clc

t=-5:0.01:5 ;

x1=exp((0.2+j*pi)*t);
x2=exp((-0.2+j*pi)*t);
x3=exp((0+j*pi)*t);

figure(2)

plot(t,real(x1))
hold on
plot(t,imag(x1),'r')
hold on
plot(t,real(x2),'--m')
hold on
plot(t,real(x3),'--k')
axis([-5 5 -2.5 2.5])
title('x(t)=e^{(\sigma+j\omega) t}')
xlabel('t')
ylabel('y(t)')
grid on

Attachment 18546

maybe you should post what is the function that you need to plot, or what values you need , maybe i'll remember something else that should be more acceptable to you and your supervisor :D
this you should get if u type that codes above ... easy you can change type and thickness of lines :D

Edit:
P.S. or if you don't know function that describe what you need, we can always (if u know in specific time intervals values of that function) approximate (very good) how doe's it act between two points... and lot's of another things :D
• Aug 13th 2010, 10:05 PM
CaptainBlack
Quote:

Originally Posted by yeKciM
although i was more in to "simulik" with matlab i think that this is what u need :D

here is one m-file (that u need to make or u can write this directly in command window)

clear all
close all
clc

t=-5:0.01:5 ;
x=cos(10*pi*t)+sin(2*pi*t);
figure(1)
plot(t,x,'r')
axis([-5 5 -2.5 2.5])
title('x(t)=cos(10 \pi t )+sin (2 \pi t')
xlabel('t')
ylabel('x(t)')
grid on

Attachment 18545

or u can do in multicolor :D like this :D

clear all
close all
clc

t=-5:0.01:5 ;

x1=exp((0.2+j*pi)*t);
x2=exp((-0.2+j*pi)*t);
x3=exp((0+j*pi)*t);

figure(2)

plot(t,real(x1))
hold on
plot(t,imag(x1),'r')
hold on
plot(t,real(x2),'--m')
hold on
plot(t,real(x3),'--k')
axis([-5 5 -2.5 2.5])
title('x(t)=e^{(\sigma+j\omega) t}')
xlabel('t')
ylabel('y(t)')
grid on

Attachment 18546

maybe you should post what is the function that you need to plot, or what values you need , maybe i'll remember something else that should be more acceptable to you and your supervisor :D
this you should get if u type that codes above ... easy you can change type and thickness of lines :D

Edit:
P.S. or if you don't know function that describe what you need, we can always (if u know in specific time intervals values of that function) approximate (very good) how doe's it act between two points... and lot's of another things :D

If you read the original post you might notice what the OP has is sample data. KDE will allow the expression of the estimated PDF as a function which can then be plotted.

CB
• Aug 13th 2010, 10:46 PM
yeKciM
Quote:

Originally Posted by CaptainBlack
If you read the original post you might notice what the OP has is sample data. KDE will allow the expression of the estimated PDF as a function which can then be plotted.

CB

ahh yes, thank you :D

that should do the trick :D i was going totally somewhere else with this, i understand that he has sample data and i assumed that discreet signal (sequence signal) and like you do reconstruction from that signal to analog signal .... we can do this :D (it can be done like that because that samples in some time intervals are like "discreet signal" and using "butterworth" filter let's say 5th order can be approximated very very good :D )

something like this :D (just reconstruction )

[b a]=butter(5, 0.01);
ynfn=filter(b,a,xsh);

but that what you wrote there is more appropriate for that issue that OP have :D