BORUTO-121

matrix_odd_even_ones_manipulation(1)

Mar 5th, 2022 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.69 KB | None | 0 0
  1. clc;clear all;
  2.  
  3. %%Manipulation: 1 => 0.5 , odd => 1, even =>0
  4.  
  5. A=[100,270;313,21];
  6. disp(f(A));
  7.  
  8. function [B]=f(A)
  9.     [rows,columns]=size(A);
  10.     B=zeros(rows,columns);
  11.     for i=1:rows
  12.         for j=1:columns
  13.             if(A(i,j)==1)
  14.               B(i,j)=0.5;
  15.             else
  16.                 if(isEven(A(i,j))==1)
  17.                     B(i,j)=0;
  18.                 else
  19.                     B(i,j)=1;
  20.                 end
  21.             end
  22.         end
  23.     end
  24.  end
  25.  
  26.  function [y]=isEven(number)
  27.         y=0;
  28.             for i=2:fix(sqrt(number))
  29.                 if(mod(number,i)==0)
  30.                     y=1;
  31.                     break;
  32.                 end
  33.             end
  34.   end
Add Comment
Please, Sign In to add comment