creating squares of images using imagesc.
10 views (last 30 days)
Show older comments
JACINTA ONWUKA
on 15 Aug 2019
Commented: JACINTA ONWUKA
on 15 Aug 2019
The idea is to produce 2D image but is not working. I want each square to correspond to different values of rho(1x101) and beta(1x101) for JCpBest(101x101). please help me
close all
clear all
% general parameters; will be fixed for all runs
L=1;
T=100;
r=0.03;
I1=0.5;
% we will be changing P and epsilon to generate grous of graphs
p=0.0005;
epsilon=0.3;
% individual policy plots will be generated by a double loop
% over beta and rho
beta=0.1;
rho=6000;
Mybeta=0:0.003:0.3;
Myrho=0:60:6000;
MycpBest=zeros(numel(Myrho),1);
JCpBest=zeros(numel(Myrho),1);
for j = 1:numel(Myrho)
rho=Myrho(j);
for ii = 1:numel(Mybeta)
beta=Mybeta(ii);
% the inner loop will be over Mycp, to find its 'best' value which
% minimmises the loss; here this value is fixed to see what happens
% create an index vector
Mycp = 0:10:100;
n = zeros(numel(Mycp),1 );
n2 = zeros(numel(Mycp),1 );
n3 = zeros(numel(Mycp),1 );
Jcp = zeros(numel(Mycp),1 );
for i = 1:numel(Mycp )
MycpCurrent=Mycp(i);
delta = 1-MycpCurrent/100 ;
tau = (1/(beta*(L+delta*p)))*log((L*(I1+delta*p))/(delta*p*(L-I1 )));
t05 =(1/(beta*(L+delta*p)))*log((L*(0.05*L+delta*p))/(delta*p*(L-0.05*L )));
I2= @(t)(L*delta*p*(exp (beta*(L+delta*p)*t)-1)) ./ (L + delta*p* exp(beta*(L+delta*p)*t ));
I3= @(t)(L*(I1+delta*p)*exp((epsilon*beta)*(L+delta*p)*(t-tau))-...
delta*p*(L -I1))./(L-I1+(I1+delta*p)*exp(epsilon*beta*(L+delta*p)*(t-tau)));
fun = @(t,MycpCurrent) MycpCurrent*L*exp(-r*t);
fun2=@(t)rho*I2(t).*exp(-r*t);
fun3=@(t)rho*I3(t).*exp(-r*t);
n(i) = integral(@(t)fun(t,MycpCurrent),0,100, 'ArrayValued',1);
n2(i)= integral(fun2,t05,tau);
n3(i)= integral(fun3,tau,100);
JCp(i)= n(i)+n2(i)+n3(i);
end
MycpBest(j)=Mycp(JCp==min(JCp));
JCpBest(j)=min(JCp);
end
end
imagesc(Mybeta,Myrho,JCpBest)
colormap jet
ylim([0 6000]);
xlim([0 0.3]);
ylabel('Loss,\rho_1');
xlabel('Secondary disease transmission rate \beta ');
title('P=0.0005')
0 Comments
Accepted Answer
Walter Roberson
on 15 Aug 2019
imagesc(Mybeta,Myrho,JCpBest)
You have invoked the form
imagesc(x, y, C)
where x and y give information about where the image is to be placed on the screen, and C is the image to be drawn.
Your Mybeta is Mybeta=0:0.003:0.3 . When used in the first argument, that would be treated the same as if you had passed in [0 0.3] in the first argument.
Your Myrho is Myrho=0:60:6000 . When used in the second argument, that would be treated the same as if you had passed in [0 6000] in the second argument.
These two parameters together mean that the center of the lower left pixel is to be placed at data units x=0 y=0, and that the center of the upper right pixel is to be placed at data units x=0.3 y=6000
Your JCpBest is JCpBest=zeros(numel(Myrho),1) which is a column vector.
You are therefore asking that the one column of data be drawn from data units x=0 to x=0.3, and y=0 to y=6000 . The result of that is going to be a vertical band, not a 2D image.
None of the three parameters you pass to imagesc() are 2D, so it is not just a matter of having accidentally used the wrong order of parameters.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!