Plotting during a loop in RStudio

前端 未结 7 2111
无人及你
无人及你 2020-12-01 18:30

I am implementing a solution to the Traveling Salesman Problem (TSP) in R (simulated Annealing) and I want to output the current best path periodically. I have searched qui

相关标签:
7条回答
  • 2020-12-01 19:13
    Plotz <- function(iter = 1000, interval = 100) {
      x <- 1:10
      p <- 0 #plot number
      for(i in 1:iter){
        y <- runif(10)
        if(i %% interval == 0) {
            p <- p + 1; plot(x, y)
            readline("Please press the Enter key to see the next plot if there is one.")
        }
      }
      return(c(x, y))
    }
    Plotz()
    
    0 讨论(0)
提交回复
热议问题