how to make a Joint PDF?
조회 수: 44 (최근 30일)
이전 댓글 표시
%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
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
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!