MATLAB: How to read these arrays into the function to input more than just one answer

arraydot syntaxfunction

a=500
alpha=[54.80,54.06,53.34]
beta=[65.59,64.59,63.62]
x=a*(tan(beta)/(tan(beta)-tan(alpha)))
It only outputs the last answer with the last set of angles and I need it at all three angles.

Best Answer

Sean
a start point could be
function x=f1(a,alpha,beta)
x=a*(tand(beta)./(tand(beta)-tand(alpha)))
end
call example
a=500
alpha=[54.80,54.06,53.34]
beta=[65.59,64.59,63.62]
x=f1(a,alpha,beta)
tan is for rad angles, tand for degree angles.
any function, to be robust, has to be able to block non coherent inputs, like chars instead of numbers, or alpha and beta with different lengths, or if you only want it to work on reals, then remove the imaginary parts.
many functions also usually include a few comment lines right below the function header, that show up when keying in 'help function_name' in MATLAB Command Window.
there are commands like
nargin
nargout
arginchk
argoutchk
varargin
varagout
to help building input output checks
the function, including a few input checks would be
function [x,err_code]x=f1(a,alpha,beta)
arginchk(3,3); % only 3 inputs
argoutchk(1,1) % only 1 output
err_list={'err message 1';'err_message 2'}
err_code=0;
if numel(a)>1
err_code=1;
disp('err_list{1}')
break;
end
% stretch angles to avoid possible size mismatch
alpha=alpha(:);beta=beta(:);
if numel(alpha)!=numel(beta)
err_code=2;
disp(err_code_list{err_code})
break;
end
x=a*(tand(beta)./(tand(beta)-tand(alpha)))
end
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG