matlab - Retain values while on loop -


can please me amend each values of 'c' , 'v' stored every time loop repeats.

c(1)=0;  v = 1;  timestep = 0.1;      while c<50          v = c*5;          c = c+1;     end  plot(timestep*(1:length(v)),v) 

well, there's vectorized version:

c = 0:50; v = 5*c;   timestep = 0.1;  plot(timestep*(1:length(v)), v) 

and looped version:

c = zeros(51,1); v = zeros(51,1);  timestep = 0.1;  ii = 1:51    c(ii) = ii;    v(ii) = 5*c(ii); end  plot(timestep*(1:length(v)),v) 

matlab ideally suited go first solution in sort of scenario, i'd suggest use vectorized version.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -