Plot a scalar as a function of a parameter

8 views (last 30 days)
Uccio
Uccio on 22 Sep 2019
Commented: Bjorn Gustavsson on 23 Sep 2019
Good morning everybody,
I would like to plot a scalar as a function of a parameter. In particular, I'd like to plot inflation volatility as a function of the parameter (phipi) of monetary policy. Inflation volatility is a vector, so defined:
for n=1:N
for t=2:T
pivolaC(1,n)=(pipiC(t,n)^2)/T;
end
end
PipiC is a function of phipi. Using plot (phipi, pivolaC) just gives me an empty figure.
(By the way, I tried the same trick using a scalar instead of a vector, that is, taking pivolaC(1,1), but the problem persists.
Could somebody help me, please?

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 22 Sep 2019
It should be as simple as:
for n = 1:N
for t = 2:T
pipiVal(1,n) = pipiC(t,n); % or however you get the phipi-values correspondin to
pivolaC(1,n) = (pipiC(t,n)^2)/T; % the values for which you calculate pivolaC
end
end
Then the plot should be:
plot(pipiVal,pivolaC)
Further, you only save away the pivolaC-value from the last step in the inner loop. The only reason I can think of in a hurry
where you need to loop anyway is if your pipiC-function stores some state-variable that is updated every time the function
is called. That's a dangerously sensitiv programming pattern, in this case it would be better to have a function that accepts an entire vector of t and loops over them. If you don't do anything like that this should be identical:
for n = 1:N
t = T;
pipiVal(1,n) = pipiC(t,n); % or however you get the phipi-values correspondin to
pivolaC(1,n) = (pipiC(t,n)^2)/T; % the values for which you calculate pivolaC
end
HTH
  3 Comments
Uccio
Uccio on 22 Sep 2019
So that, at the endo of the day, inflation volatility will be affected by change in "phipi" only thorugh the matrix BC and the vector KAPPAC.
Bjorn Gustavsson
Bjorn Gustavsson on 23 Sep 2019
It's not exactly clear what is the problem, to me this:
subplot(2,2,1)
imagesc(zzC)
subplot(2,2,4)
imagesc(pipiC)
subplot(2,2,2)
plot(zzC(:,1),pipiC(:,1),'-',zzC(:,1),pipiC(:,1),'.','markersize',15)
subplot(2,2,3)
plot(zzC(12,:),pipiC(12,:),'-',zzC(12,:),pipiC(12,:),'.','markersize',15)
your zzC matrix as a pseudo-colour image in the top left panel, the pipiC matrix as a pseudo-colour image in the bottom right panel, the first column of zzC and pipiC in the top right panel and the 12th row in the bottom left.
HTH

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!