User defined function to output matrix
20 ビュー (過去 30 日間)
古いコメントを表示
I am in need of some help with a user defined function. I have it so it will output a column array of zeros however I need to function to fill the array dependant on a number of conditions and I have no idea how to get from where I am to where I need to be.
function [Q] = O_R_B(H)
%Operating rule B for varying dam heights
% Determining the usage rates for the dam for different dam heights
H_max = 30.9; %dam height in m (scaled 1:300)
Q_out = 138; %normal output rate
Q = zeros(length(H),1);
for k = 1:length(H)
if H >= 1*H_max;
Q = string('issue warning');
elseif H >= 0.9*H_max;
Q(k) = 4 * Q_out;
elseif H < 0.9*H_max & H>= 0.85*H_max;
Q(k) = 2* Q_out;
elseif H < 0.85*H_max & H>= 0.4*H_max;
Q(k) = Q_out;
elseif H < 0.4*H_max & H>= 0.2*H_max;
Q(k) = 0.5*Q_out;
else H< 0.2*H_max;
Q(k) = 0;
end
end
end
0 件のコメント
採用された回答
James Tursa
2017 年 9 月 23 日
編集済み: James Tursa
2017 年 9 月 23 日
You need to index H also in your code. E.g.,
if H(k) >= 1*H_max;
error('H too large');
elseif H(k) >= 0.9*H_max;
Q(k) = 4 * Q_out;
:
etc
6 件のコメント
James Tursa
2017 年 9 月 23 日
編集済み: James Tursa
2017 年 9 月 23 日
You could issue a warning and fill the element with NaN. E.g.,
if H(k) >= 1*H_max;
Q(k) = NaN;
warning(sprintf('H(%d) element too large',k));
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!