Im trying to validate the input string in my function using error(msg), can anyone help?
function [amino_acid_chain] = synthesize(mRNA)
% throws an error if input string 'mRNA' is not a member of y.
y = ['g','c','a','u','G','C','A'',U'];
x = ismember(mRNA,y);
% I want to use this error if anything comes up logical 0 in x
msg = 'Error occurred.';
error(msg)

댓글 수: 3

Note that square brackets are a concatenation operator, so your example:
y = ['g','c','a','u','G','C','A','U'];
is exactly equivalent to the much simpler:
y = 'gcauGCAU';
Rik
Rik 2019년 5월 7일
Also note that it is probably easier for the rest of your script to pick either upper or lower case. You can use the upper or lower function to convert your input, then you can continue your function with only one case to worry about.
I have a habit of over complicating things! thanks.
Ive already converted input to a cell array in groups of three and uppercase.

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

 채택된 답변

Rik
Rik 2019년 5월 7일

0 개 추천

if any(~x)
error(msg)
end

추가 답변 (0개)

카테고리

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

태그

질문:

2019년 5월 7일

댓글:

2019년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by