How to create a function that produces 2 histograms?
Show older comments
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.
Answers (2)
Steven Lord
on 14 Dec 2022
0 votes
2 Comments
Jakub
on 14 Dec 2022
Steven Lord
on 14 Dec 2022
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.
tiledlayout(2,1);
[X,Y,Z] = peaks(20);
% Tile 1
nexttile
surf(X,Y,Z)
% Tile 2
nexttile
contour(X,Y,Z)
Categories
Find more on Histograms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!