Why am I getting a parse error at the logical operator &&?

조회 수: 13 (최근 30일)
Kristen O'Mara
Kristen O'Mara 2018년 5월 3일
댓글: Kristen O'Mara 2018년 5월 3일
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.

채택된 답변

Star Strider
Star Strider 2018년 5월 3일
You’re not incrementing the loop.
Try this:
m1 = randi([-1 1], 20, 1); % Create Data
m2 = randi([-1 1], 20, 1); % Create Data
for i = 1:numel(m1)
if m1(i) >= 0 && m2(i) >= 0
nucleotides(i) = 'A';
elseif m1(i) < 0 && m2(i) >= 0
nucleotides(i) = 'C';
elseif m1(i) >= 0 && m2(i) < 0
nucleotides(i) = 'G';
elseif m1(i) < 0 && m2(i) < 0
nucleotides(i) = 'T';
end
end

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 5월 3일
In this line
if m1(i) >= (##) && m2(i) >= 0
You forget to write a number at (##).
  댓글 수: 4
Ameer Hamza
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
Kristen O'Mara 2018년 5월 3일
Thanks sm that helps!

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

카테고리

Help CenterFile Exchange에서 Nucleotide Sequence Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by