MATLAB: Finding odd and even values without functions evenhomeworkidentifyodd Is it possible to identify if a value is even or odd using for loops instead of using a function (Ex. mod)? If possible, can someone show me? Best Answer What about dividing?while 1 a = a/2; if abs(a-1) < 0.01 % if very close to '1' disp('even') break; elseif a < 1 % if smaller than '1' disp('odd') break; endend Related SolutionsMATLAB: See sequences in array A = [1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1]A([false, all([A(1:end-2); A(2:end-1); A(3:end)] == 1), false]) = 0 %replace all 1s in between between two 1s by 0Or since it doesn't matter if you replace a 0 by a 0:A([false, all([A(1:end-2); A(3:end)] == 1), false]) = 0 %replace any value between two 1s by a 0 MATLAB: How to remove zero values. the program is correct but i need only even and odd number Using loops is a pointlessly complicated and slow way to solve such a simple task:>> n = 9;>> odd = 1:2:nodd = 1 3 5 7 9>> even = 2:2:neven = 2 4 6 8and to get the sum: >> sum(odd) ans = 25 Related QuestionArray of 1 and 0 to decimalHow the computation happening : sum(A~=0,2)Dicarding the mth binary digitIsempty is allways zeroWarning: Unsuccessful read: The specified amount of data was not returned within the Timeout period.Find matching rows based on specific column values
Best Answer