MATLAB Answers

How to pass the same function to different columns?

3 views (last 30 days)
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 Comments
Armando MAROZZI
Armando MAROZZI on 3 Apr 2020
Yes, sorry, just edited. I want to treat each call as totally separate

Sign in to comment.

Accepted Answer

Rik
Rik on 3 Apr 2020
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

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!