필터 지우기
필터 지우기

isolate the odd and even integers in the matrix.

조회 수: 6 (최근 30일)
CaiX
CaiX 2019년 9월 8일
댓글: madhan ravi 2019년 9월 8일
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.

답변 (1개)

madhan ravi
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
CaiX
CaiX 2019년 9월 8일
thank you for the response :) However, is it possible to display the even and odd integers afterwards? I tried doing it but the if function doesn't work:
function [B,evenvector,oddvector] = problem2
A = input('Enter Values: ');
B = rem(A,2);
evenvector = A(B == 0);
oddvector = A(B ~= 0);
if B == 0
disp('evenvector')
else
disp('oddvector')
end
I would like to achieve this kind of output:
problem2()
Enter Values: [4 8 3 6 5 10 7 14]
evenvector:
4 8 6 10 14
oddvector:
3 5 7
madhan ravi
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by