isolate the odd and even integers in the matrix.
조회 수: 5 (최근 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!