fork download
  1. # your code goes here
  2. A <- matrix(1:25, 5, 5);
  3. B <- matrix(1:25, 5, 5);
  4. C <- matrix(1:25, 5, 5);
  5.  
  6. A[1,1] = 0.228; A[1,2] = 0.285; A[1,3] = 0.285; A[1,4] = 0.285; A[1,5] = 0.380;
  7. A[2,1] = 0.228; A[2,2] = 0.285; A[2,3] = 0.570; A[2,4] = 0.380; A[2,5] = 0.228;
  8. A[3,1] = 0.380; A[3,2] = 0.285; A[3,3] = 0.228; A[3,4] = 0.380; A[3,5] = 0.285;
  9. A[4,1] = 0.285; A[4,2] = 0.285; A[4,3] = 0.570; A[4,4] = 0.380; A[4,5] = 0.380;
  10. A[5,1] = 0.380; A[5,2] = 0.228; A[5,3] = 0.285; A[5,4] = 0.285; A[5,5] = 0.380;
  11.  
  12.  
  13. B[1,1] = 0.383; B[1,2] = 0.174; B[1,3] = 0.535; B[1,4] = 0.700; B[1,5] = 0.396;
  14. B[2,1] = 0.404; B[2,2] = 0.785; B[2,3] = 0.346; B[2,4] = 0.838; B[2,5] = 0.380;
  15. B[3,1] = 0.591; B[3,2] = 0.554; B[3,3] = 0.260; B[3,4] = 0.229; B[3,5] = 0.361;
  16. B[4,1] = 0.176; B[4,2] = 0.865; B[4,3] = 0.423; B[4,4] = 0.166; B[4,5] = 0.349;
  17. B[5,1] = 0.132; B[5,2] = 0.018; B[5,3] = 0.456; B[5,4] = 0.684 ; B[5,5] = 0.150;
  18.  
  19. i <- 1;
  20. j <- 1;
  21.  
  22. #Como eu consigo retornar uma terceira
  23. #Matriz (C) que retorna 1 se o valor na mesma
  24. #posicao da matrix B for menor ou igual do que o da
  25. #matriz(A) e 0 se for maior ?
  26.  
  27. while(i < 6)
  28. {
  29. j <- 1;
  30. while(j < 6){
  31. C[i,j] <- 1;
  32. if (A[i,j] <= B[i,j]){
  33. C[i,j] <- 0;
  34. }
  35. j <- j + 1;
  36. }
  37. i <- i + 1;
  38. }
  39.  
  40. C;
  41.  
  42. #OUTRA SOLUÇÃO BEM PRÁTICA
  43. #D <- ifelse(B <= A, 1, 0);
  44. #D;
Success #stdin #stdout 0.46s 22824KB
stdin
Standard input is empty
stdout
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    0    0    0
[2,]    0    0    1    0    0
[3,]    0    0    0    1    0
[4,]    1    0    1    1    1
[5,]    1    1    0    0    1