Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有人可以帮我修改一下,以便每次循环重复时都存储“c”和“v”的每个值。
c(1)=0; v = 1; timestep = 0.1; while c<50 v = c*5; c = c+1; end plot(timestep*(1:length(v)),v)
好吧,有矢量化版本:
c = 0:50; v = 5*c; timestep = 0.1; plot(timestep*(1:length(v)), v)
和循环版本:
c = zeros(51,1); v = zeros(51,1); timestep = 0.1; for ii = 1:51 c(ii) = ii; v(ii) = 5*c(ii); end plot(timestep*(1:length(v)),v)
Matlab 非常适合在这种情况下使用第一个解决方案,因此我建议您使用矢量化版本。