向量化求和的 for 循环
大家好
我如何矢量化这个 for 循环?
t_rebuilt=linspace(0,1,length(inner_freq));
for ii=1:1:length(inner_freq)-1;ii=ii+1;
aa_sig_rebuilt=inner_freq(ii,2)*cos(2*pi*t_rebuilt*inner_freq(ii,1)+inner_freq(ii,3));
aa_sig_combined=aa_sig_combined+aa_sig_rebuilt;
end;
我尝试用下面的行替换它,看看它是否有效,但我只是得到一条直线
aa_sig_rebuilt=inner_freq(ii,2).*cos(2*pi*t_rebuilt*inner_freq(ii,1)+inner_freq( ii,3));
Greetings All
How can I vectorizing this for loop?
t_rebuilt=linspace(0,1,length(inner_freq));
for ii=1:1:length(inner_freq)-1;ii=ii+1;
aa_sig_rebuilt=inner_freq(ii,2)*cos(2*pi*t_rebuilt*inner_freq(ii,1)+inner_freq(ii,3));
aa_sig_combined=aa_sig_combined+aa_sig_rebuilt;
end;
I tried replacing it with the line below to see if it worked but I just get a straight line
aa_sig_rebuilt=inner_freq(ii,2).*cos(2*pi*t_rebuilt*inner_freq(ii,1)+inner_freq(ii,3));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来
t_rebuilt
是一个由时间点组成的 1×N 向量,您希望在该时间点计算一组三角函数,其参数在 M×3 矩阵的行中定义内部频率
。然后您希望将所有这些结果添加到单个组合信号中。您可以在不使用 for 循环的情况下执行此操作,如下所示:然后您可以按如下方式绘制结果:
It appears that
t_rebuilt
is a 1-by-N vector of time points at which you want to evaluate a set of trigonometric functions with parameters defined in the rows of the M-by-3 matrixinner_freq
. Then you want to add all these results into a single combined signal. You can do this without a for loop as follows:You can then plot the result as follows:
试试这个
Try this