有没有一种方法可以将代码矢量化成与我下面的形式相同的代码?
for k=1:length(channel_cuttoffs)
[b a] = butter(5,channel_cuttoffs(k));
pulse = filtfilt(b,a,pulse);
eyediagram(downsample(pulse,10),3)
endpulse为10000x1,channel_cuttoffs为1x5。
发布于 2014-12-23 19:55:18
您可以使用arrayfun来向量化代码。
类似于:
[b a] = arrayfun(@(x), butter(5, x), channelcuttoffs);
pulse = arrayfun(@(x, y), filtfilt(x, y, pulse), b, a);我不认为你可以对眼图做任何事情,因为它创建的是一个图形,而不是一个数字输出。
然而,应该注意的是,arrayfun速度很慢,更多细节请参见:arrayfun can be significantly slower than an explicit loop in matlab. Why?和http://www.mathworks.com/matlabcentral/newsreader/view_thread/253596。因此,您最好像在问题中那样使用循环。
https://stackoverflow.com/questions/27616991
复制相似问题