isolate the odd and even integers in the matrix.
6 次查看(过去 30 天)
显示 更早的评论
Hi, we were tasked to isolate odd and even integers in a matrix given by the user. I tried doing it but it keeps on getting an error at line 3. Here's what I've done so far:
function [B,C1,C2] = problem2
A = input('Enter Values: ');
B = rem(A,2);
if B == 0
disp('even')
isolate(B == 0);
else
disp('odd')
isolate (B ~= 0);
end
The command window shows:
>> problem2()
Enter Values: 4 8 3 6 5 10 7 14 (This is the number I entered to test the program)
Error using problem2 (line 3)
Error: Unexpected MATLAB expression.
0 个评论
回答(1 个)
madhan ravi
2019-9-8
编辑:madhan ravi
2019-9-8
function [B,Even,Odd] = problem2
A = input('Enter Values: '); % input must be [4,2,6,3,5] for example , don't forget the [ ]
B = rem(A,2);
Even=A(B == 0);
Odd=A(B ~= 0);
end
2 个评论
madhan ravi
2019-9-8
[B,T] = problem2
function [B,T] = problem2
A = input('Enter Values: ');
B = rem(A,2);
T=table;
T.evenvector = A(B == 0);
T.oddvector = A(B ~= 0);
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!