-3

Can anyone explain to me how to generate the Weibull distribution parameters k and c, in Matlab?

I have a file of 8000 data of wind speed, and I'd like to do the following:

  1. Generate the Weibull's k and c parameters of those.
  2. Plot the probability density function against the wind speed.

I am new in Matlab and have not yet been able to do this.

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
Zay
  • 115
  • 2
  • 6

1 Answers1

3

If you have the Statistics toolbox, you can use fitdist:

pd = fitdist(x,'Weibull')

where x is your data. I'm guessing it should return the parameters a and b in:

enter image description here

You can then calculate the pdf (and plot it) using the pdf function. There are some examples (albeit for a normal distribution) in the documentation for fitdist.

am304
  • 13,758
  • 2
  • 22
  • 40
  • hello.. Thanks a lot for the reply.. My x is around 20thousand data, and when I run with fitdist I obtain the following error:>>pd=fitdist(x,'Weibull'); Error using fitdist (line 102) X must be a numeric column vector..... Please advice me more..:( – Zay Sep 26 '13 at 17:05
  • hi, i think the problem is that i am not being able to import my data from he libre office calc into matlab!! hence all that problem... any advice? – Zay Sep 26 '13 at 18:51
  • The error message says that your `x` is not numeric data. Can you tell us what the first, say, 10-20 elements of x look like? – am304 Sep 26 '13 at 20:00
  • To import the data from LibreOffice, save your speadsheet as a csv file, and then use `csvread`. – am304 Sep 26 '13 at 20:03
  • >> filename='z.csv'; >> M=csvread(filename) Error using csvread (line 37) File not found. hi.. i already used the command csvread but in vain.. the above error.. the elements of x are the wind speed. – Zay Sep 26 '13 at 20:45
  • If it says "file not found", then it's no surprise that `fitdist` doesn't work... you don't have any data to pass the function to!! Make sure your *.csv file exists and MATLAB can find it (i.e. it's on the MATLAB path or in your current directory). You can check with the `exist` function (see for details). – am304 Sep 27 '13 at 08:37
  • hi.. Again thanks a lot for the patience taken.. When i do exist and add my file name i got this..( >> exist plai.txt ans = 0 >> exist z.dat ans = 0).. all these files is on my desktop. I have saved my file in .txt and try to import the data but in vain.. yes if I cannot even import my data so i obviously cannot use ftdist...i tried ftdist with some simple numbers and it work. now my problem is how to insert my data into matlab.. thanks. – Zay Sep 27 '13 at 09:26
  • If your files are on your desktop and your current directory in MATLAB is not your desktop, it's not surprising MATLAB can't find them. Put them in the directory your are running your MATLAB script/function from, and it should work. – am304 Sep 27 '13 at 09:31
  • Also my data is only in one column.. I have saved it as txt and still the data is not imported..:( i am now in the directory where my file is.. but the problem is how do i call the file in my command window? – Zay Sep 27 '13 at 10:10
  • It's really not difficult, save it as a CSV file, and use csvread to import the data into MATLAB. It doesn't get any simpler than that... I don't know what else to say – am304 Sep 27 '13 at 10:12
  • >> filename='plai.csv'; >> M=csvread(filename) Error using dlmread (line 141) Mismatch between file and format string. Trouble reading number from file (row 1722u, field 1u) ==> M\n Error in csvread (line 50) m=dlmread(filename, ',', r, c); – Zay Sep 27 '13 at 10:18
  • Does the CSV file contain only numeric values? Have you inspected it before trying to import the data? What is in row 1722? – am304 Sep 27 '13 at 10:20
  • yesh it contain only numeric data and that too only 1 column..there is nothing in row 1722. – Zay Sep 27 '13 at 10:48
  • Can you make the file available? – am304 Sep 27 '13 at 11:04
  • hi.. i finally inserted the data in matlab, using importdata(filename)... but now when i do >> pd=fitdist(M,'Weibull') Error using ProbDistUnivParam.fit (line 92) All X values must be in the interval (0,Inf). Error in fitdist (line 123) pd = ProbDistUnivParam.fit(x,distname,'cens',cens,'freq',freq,args{:}); – Zay Sep 27 '13 at 11:14
  • Well, as the error message suggests, it looks like some of your values are negative – am304 Sep 27 '13 at 11:23
  • no.. all my values are wind speed.. hence all positive..:( wht should i do? – Zay Sep 27 '13 at 11:25
  • also i have 99thousand data in all so why only 1721 are shown? – Zay Sep 27 '13 at 11:27
  • I don't know, I can't see your data... Only you can answer that question. I have asked you whether you had inspected the spreadsheet before trying to import it in MATLAB. – am304 Sep 27 '13 at 13:31
  • yesh i have checked the spreadsheet fact is i used libre office calc..but i saved it as .csv..i have 99thousnd data but only 1721 imported and also the error ...can we chat? – Zay Sep 27 '13 at 14:13