Why am I getting a parse error at the logical operator &&?
显示 更早的评论
For some reason I am getting a parse error at && which will not allow my code to run.
function [nucleotides] = BMEactivity(m1, m2)
for i = 1:m1(end)
if m1(i) >= && m2(i) >= 0
nucleotides(i) = 'A';
elseif m1(i) < 0 && m2(i) >= 0
nucleotides(i) = 'C';
elseif m1(i) >= 0 && m2(i) < 0
nucleotides = 'G';
elseif m1(i) < 0 && m2(i) < 0
nucleotides(i) = 'T';
else
end
end
end
Also, I'm not quite sure if this is the correct syntax in the for loop for indexing to the last element of the array. It would be ideal if there was one expression that let me index to the end of m1 and m2 simultaneously.
采纳的回答
更多回答(1 个)
Ameer Hamza
2018-5-3
In this line
if m1(i) >= (##) && m2(i) >= 0
You forget to write a number at (##).
4 个评论
Kristen O'Mara
2018-5-3
Steven Lord
2018-5-3
If you want your for loop to iterate through all the elements in m1, you don't want the upper limit to be m1(end). If m1(end) were less than 1, the body of your for loop wouldn't execute at all and so the nucleotides variable would indeed not be defined.
Use numel(m1) as the upper limit of your for loop instead. The numel function returns the NUMber of ELements in your array.
Ameer Hamza
2018-5-3
编辑:Steven Lord
2018-5-3
Also, consider pre-allocation. For example before for loop, initialize nucleotides with zeros.
nucleotides = zeros(1, numel(m1));
[SL: fixed typo]
Kristen O'Mara
2018-5-3
类别
在 帮助中心 和 File Exchange 中查找有关 Nucleotide Sequence Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!