Why am I getting a parse error at the logical operator &&?
2 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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
0 件のコメント
その他の回答 (1 件)
Ameer Hamza
2018 年 5 月 3 日
In this line
if m1(i) >= (##) && m2(i) >= 0
You forget to write a number at (##).
4 件のコメント
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]
参考
カテゴリ
Help Center および File Exchange で Robust Control Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!