How to create a for loop for this?
1 次查看(过去 30 天)
显示 更早的评论
I haven't worked with for loops in a while and can't remember how to set up the for loop for what I'm trying to do. I have an vector, "w", of values and I want to find the difference between values. How would I set up a for loop to do what I did in the last section in my code where I find dw1 through dw3? 

0 个评论
采纳的回答
Voss
2022-4-5
编辑:Voss
2022-4-5
No loop is necessary; you can use diff (see below).
n = 4;
startFrequency = 0.25;
endFrequency = 1;
frequencies = linspace(startFrequency,endFrequency,n);
w = 2*pi*frequencies;
% no loop necessary:
dw = diff(w)
% if you want to use a loop anyway, here's one:
for ii = 1:n-1
dw(ii) = w(ii+1)-w(ii);
end
dw
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!