Separating a one column variable based on value

4 Ansichten (letzte 30 Tage)
Elizabeth Kahler
Elizabeth Kahler am 16 Mär. 2016
Kommentiert: Image Analyst am 16 Mär. 2016
I am totally new to Matlab, which means the solution to my problem is likely very simple. I have a dataset of daily precip, runoff, and Ep values for thirty years for a specific catchment. What I need is thirty plots of daily discharge (Q) vs the exceedance probability for the discharge value. I actually found a script that seems to do the latter, but the problem is that when I tell it to perform the function/plotting on the variable "Q" it takes all thirty years and performs the sorting and everything else needed to make the plot. So instead of having thirty lines on one plot, I have one meaningless line/plot.
I have the years stored in another variable, so I would like to tell Matlab to perform the exceedance probability plot script for each year. An extra problem with doing this is that I'm using hydrologic years, so I have already converted the date format to Julian days, where 1 represents October 1, and 365 or 366 represents September 30. Is there some way to tell Matlab to loop or perform the same script on every chunk of data represented in the year variable as consecutive dates of 1-365? Or some other perhaps more intuitive way of doing this? I've attached the copied script I'm using for the exceedance plot.
function [eX] = eprob(X) % eprob: calculates the exceedance probability for n column vectors in the % array [m n] X, where m are the observations. The probability is % output in percent. eX is output as a structure (see Output Arguments). % % Usage: eX = eprob(X); % % Input Arguments: % % X - [m n] vector where m are the observations and n are the number of % datasets for which the exceedance probability is to be calculated. % The size of m must be the same for all datasets. % % Output Arguments: % % eX - structure array containing all output data % ex.data - input data X [m n] % ex.r - the number of rows, m % ex.c - the number of datasets (columns), n % ex.sort - X input data sorted in descending order % ex.rank - single column matrix of the sorted data rank % ex.eprob - calculated exceedance probability (rank/m+1) % % Example: % % X = randn(1000,1) % create randomly distributed dataset with 1000 values % eX = eprob(X); % % Author: Jeff A. Tuhtan % e-mail address: jtuhtan@gmail.com % Release: 1.0 % Release date: 20.08.2010
Scap = 10; % active operational energy storage capacity % Scap = StorCapPercent eX average annual generation eX = struct;
eX.data = X; eX.r = size(eX.data,1); % no. rows eX.c = size(eX.data,2); % no. cols
eX.sort = sort(eX.data,'descend'); % sorts data in descending order eX.rank = (1:eX.r)'; eX.eprob = zeros(eX.r,1); eX.eprob = eX.rank./(eX.r+1);
% plotting eeXceedance probability curve (in %) plot(eX.eprob,eX.sort,'r-','LineWidth',2); xlabel('Exceedance Probability','FontWeight','Bold'); ylabel('Value','FontWeight','Bold');

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by