How to pass the same function to different columns?
2 次查看(过去 30 天)
显示 更早的评论
I would like to pass the same function to all the columns of an object.
I tried this code but it doesn't work
for j = 1:3
autocorr(VAR.res(:,j))
end
where basically I wanted to tell MATLAB "compute autocorrelation for all the 3 columns of VAR.res".
What did I do wrong?
Thanks
2 个评论
Rik
2020-4-3
That is not an internal Matlab function, unless you meant autocorr. Also, do you want to treat each call as totally separate, or do you want to correlate those columns in some way as well?
采纳的回答
Rik
2020-4-3
You need to specify the target axes, otherwise the function will use gca for each call, so that will be the same axes.
figure(1),cfl(1)
n_cols=size(VAR.res,2);
for col = 1:n_cols
ax=subplot(1,n_cols,col);
autocorr(ax,VAR.res(:,col))
end
更多回答(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!