how to make a Joint PDF?

82 ビュー (過去 30 日間)
Mukhtar Daud
Mukhtar Daud 2020 年 11 月 5 日
コメント済み: Peter Perkins 2020 年 11 月 19 日
%reading the Excel file and storing in variable k.
[~,~,k] = xlsread('Copy_of_SPX_data.xlsx');
%reading the .txt file and storing it in variable A.
A = importdata('Sunspot_data.txt');
DateString = k(2:5410,1);
formatIn = 'mm/dd/yyyy';
x = log(datenum(DateString,formatIn));
y = log(cell2mat(k(2:5410,2)));
y1=A(66109:66109+length(y)-1,5);
figure(1)
[f,x1] = hist(y,50);
bar(x1,f/trapz(x1,f));
title('StockMarket pdf')
ylabel('StockMarket')
xlabel('Daily stock value')
grid on
figure(2)
[f1,x2]=hist(y1,50);
bar(x2,f1/trapz(x2,f1))
title('Sunspot pdf')
ylabel('Sunspot porbaility')
xlabel('Sunspot daily value')
grid on
X=[y,y1];
[n,c]=hist3(X);
figure(3)
contour(c{1},c{2},n)
title('Sunspot and StockMarket joint pdf')
ylabel('Stockmarket')
xlabel('Sunspot daily probaility')
***Here is my code, I'm trying to add the first pdf to the second one and create a joint pdf, the pdf is wokring but looks very bad and wrong, im not an expered coder so i don't know what to do?
  1 件のコメント
Peter Perkins
Peter Perkins 2020 年 11 月 19 日
Orthogonal to the actual question, importdata is probably not the thing to use. I suggest looking at readtable or readtimetable. I suspect that importdata is the reason why you had to use cell2mat. You shouldn't need to. In addition, this
x = log(datenum(DateString,formatIn));
seems odd. Using readtable would avoid datenums, which you want to avoid, but also you are taking the logs of numbers with a c ompletely arbitrary origin. Not sure why you'd need to use a log scale for a time axis.

サインインしてコメントする。

回答 (1 件)

Reshma Nerella
Reshma Nerella 2020 年 11 月 10 日
編集済み: Reshma Nerella 2020 年 11 月 10 日
Hi,
I did not get the term joint pdf.
In case joint pdf means getting all pdfs on the same figure, you can try this out.
[f,x1] = hist(y,50);
bar(x1,f/trapz(x1,f));
title('StockMarket pdf')
ylabel('StockMarket')
xlabel('Daily stock value')
grid on
hold on %to add new plot to same axes i.e second and third pdf
[f1,x2]=hist(y1,50);
bar(x2,f1/trapz(x2,f1))
title('Sunspot pdf')
ylabel('Sunspot porbaility')
xlabel('Sunspot daily value')
grid on
[n,c]=hist3(X);
contour(c{1},c{2},n)
title('Sunspot and StockMarket joint pdf')
ylabel('Stockmarket')
xlabel('Sunspot daily probaility')
hold off %to prevent other plots from using the same axes
You can also add legend to the plots to differentiate each other

Community Treasure Hunt

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

Start Hunting!

Translated by