MATLAB: How to make function which gets as input arguments matrix of chars work

amino acidsbioinformaticsdnaMATLAB

I am trying to write function which converts RNA codons into amino acids. The codons is matrix of chars for example 10×3. There is still is an error output arguments "aminoacids" (and maybe others) not assigned during call to "translation". I don/t know how to fix it. Tried to by replacing aminoacids(m) with result(m) and then typing just above the end of the function "aminoacids=result" but it still doesn't work. Please help.
function [aminoacids] = translation(codons)
for m = 1:length(codons)
switch (codons(m))
case {'GCU', 'GCC', 'GCA', 'GCG'}
aminoacids(m) = 'Ala';
case {'UGU', 'UGC'}
aminoacids(m) = 'Cys';
case {'GAU', 'GAC'}
aminoacids(m) = 'Asp';
case {'GAA', 'GAG'}
aminoacids(m) = 'Glu';
case {'UUU', 'UUC'}
aminoacids(m) = 'Phe';
case {'GGU', 'GGC', 'GGA', 'GGG'}
aminoacids(m) = 'Gly';
case {'CAU', 'CAC'}
aminoacids(m) = 'His';
case {'AUU', 'AUC', 'AUA'}
aminoacids(m) = 'Ile';
case {'AAA', 'AAG'}
aminoacids(m) = 'Lys';
case {'UUA', 'UUG', 'CUU', 'CUC', 'CUA', 'CUG'}
aminoacids(m) = 'Leu';
case 'AUG'
aminoacids(m) = 'Met';
case {'AAU', 'AAC'}
aminoacids(m) = 'Asn';
case {'CCU', 'CCC', 'CCA', 'CCG'}
aminoacids(m) = 'Pro';
case {'CAA', 'CAG'}
aminoacids(m) = 'Gln';
case {'CGU', 'CGC', 'CGA', 'CGG', 'AGA', 'AGG'}
aminoacids(m) = 'Arg';
case {'UCU', 'UCC', 'UCA', 'UCG', 'AGU', 'AGC'}
aminoacids(m) = 'Ser';
case {'ACU', 'ACC', 'ACA', 'ACG'}
aminoacids(m) = 'Thr';
case {'GUU', 'GUC', 'GUA', 'GUG'}
aminoacids(m) = 'Val';
case 'UGG'
aminoacids(m) = 'Trp';
case {'UAU', 'UAC'}
aminoacids(m) = 'Tyr';
case {'UAA', 'UAG', 'UGA'}
aminoacids(m) = 'Stop';
end
end
aminoacids = aminoacids;
end

Best Answer

Kevin's Answer Is Correct Of Course,
But If that Was The Problem You Were Facing You Would Have Had A Different Error About Indexing Mismatch or SWITCH expression must be a scalar or a character vector.
I suspect you called the translation function with a character vector input, something like:
a = translation('GCUGAC')
the problem is that when you test the value at index m of that codons vector you get a single character 'G', 'C', 'U' or 'A' which is never equal to any of the sequences in your switch case.
what you need to do is send the codon sequence as a cell array of character vectors:
a = translation({'GCU' 'GAC'})
then you need to index that inside the loop with curly bracers like kevin said:
switch (codons{m})
and the output should also be a cell array proobably (like kevin suggested)
moreover, it's always a good idea to add a default value for output arguments, add
aminoacids = {};
just before the loop.