How to create a function that produces 2 histograms?

I have a dataset with 2 columns and 9862 rows.
I need to make a figure consisting of two panels where the upper panel is the histogram of one column and the lower panel is the histogram of the other column.
Dd = RiverData(:,1); % daily discharge
Dr = out(); % daily rainfall
function histfunction(Dd,Dr)
% histogram function takes in the daily discharge and rainfall and histograms them
% Dd = Daily discharge, Dr = Daily rainfall
plot(Dr,Dd)
end
So far, I've come up with this (I'm only making one right now but I can't even manage that), but clearly I have made some sort of mistake and I can not figure it out.

답변 (2개)

Steven Lord
Steven Lord 2022년 12월 14일

0 개 추천

Use tiledlayout and call histogram twice, once for each tile in the tiled layout.

댓글 수: 2

how would i incorporate this into a function though? i am very new to matlab
Most functions in MATLAB include examples on their documentation pages. The tiledlayout documentation page to which I linked above has 14 examples and the histogram documentation page has 10.
Part of the purpose of those examples is to teach users how to use those functions, but another part of their purpose is to serve as starting points. Find examples on those pages that look close to what you want to do, copy them into your code, and modify them so they meet your needs. Once you have them working as a script, create a function file and put that code inside it. You'll need to decide what input and output arguments your function should have, but the documentation describes how to specify those in your function's definition statement.

댓글을 달려면 로그인하십시오.

I'd use tiledlayout. Rather than surf or countour, use histogram.
tiledlayout(2,1);
[X,Y,Z] = peaks(20);
% Tile 1
nexttile
surf(X,Y,Z)
% Tile 2
nexttile
contour(X,Y,Z)

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

제품

질문:

2022년 12월 14일

댓글:

2022년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by