Plot a scalar as a function of a parameter

조회 수: 5 (최근 30일)
Uccio
Uccio 2019년 9월 22일
댓글: Bjorn Gustavsson 2019년 9월 23일
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?

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2019년 9월 22일
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
Uccio
Uccio 2019년 9월 22일
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 2019년 9월 23일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by