contour plot not working after using the help example

please help me. My contour is not working. I follow step by step example in Matlab HELP to plot my own work. it keep showing this message. The code is giving below. Thank you.
Index exceeds matrix dimensions.
Error in ==> contour>parseargs at 135
if ischar(args{end})
Error in ==> contour at 67
[pvpairs,args,msg] = parseargs(args); %#ok
clear all
close all
R0 = beta / gamma * (alpha * gamma + gamma * R * (1 - alpha)) + tau;
alpha = 0.4;
beta = 0.25;
gamma = 0.2;
omega = 0.2;
xi = 0.05;
R1 = linspace(0,1,100);
tau1 = linspace(0,1,10);
[tau R] = meshgrid(tau1,R1);
mesh(tau,R,R0) %interpolated
axis tight; hold on
plot(tau,R,R0,'.','MarkerSize',15) %nonuniform

8 Comments

You have not used contour in the above code. First, is the above code running ? Is it showing the error ypu have mentioned?
I am sorry. There are two examples I am reading on how to plot contour. The one I posted is the one I followed using the help example in mesh. Below is the code I am try to get the plot. It is also giving me the error message. Please help me I am in need of the code. Thank you for quick responses.
clear all
close all
% Paramter values
alpha = 0.4;
beta = 0.25;
gamma = 0.2;
omega = 0.2;
xi = 0.05;
% Parameter space
tau1 = linspace(0,0.1,100);
R1 = linspace(0,2,100);
[tau R] = meshgrid(tau1,R1);
% Basic reproductive number
R0 = beta / gamma * (alpha * gamma + gamma * R * (1 - alpha) + tau / xi +...
R * omega) ./ (tau / xi + omega + gamma);
% Desnity plot with contours
figure(1)
pcolor(tau1,R,R0);
shading flat
hold on
contour(tau,R,R0,7,'LineColor',[0.3 0.3 0.3],'ShowText','on')
hold on
colorbar
caxis([min(min(R0)) max(max(R0))])
title('R_0')
xlabel('\tau')
ylabel('R')
The code above works for me in r2020a.
What version of Matlab are you using?
If I had to make a bet, it would be that you named a script file with some name. The name of that script might have been something dangerous, like contour. After all, you were trying to do a contour plot. That is a bad thing to do, as then MATLAB gets confused when you try to use the actual code.
So exactly what did you name that script?
You would get better help is, when you get an error message, you report the ENTIRE error message text. Thus EVERYTHING IN RED. Then we could look at it and know what you did. But when you report an abbreviated version, with only what you think seems important, invariably the person chooses to report the wrong information. So instead we need to get you to tell us what you did.
Adam Danz. I am using the R2007b version.
John D'Errico thank you for your responses. I named the script, contour plot.
You named the script "contour plot.m" with a space between the two words? Is that how I should read what you said? If so, you need to realize that is not a valid name for a script in MATLAB.
Thank you very much. It is working now. I changed the script's name. Thank you. I am grateful. I look forward to responses to my second code.

Sign in to comment.

Answers (0)

Categories

Asked:

on 28 May 2020

Edited:

on 28 May 2020

Community Treasure Hunt

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

Start Hunting!