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 件のコメント

KSSV
KSSV 2020 年 5 月 28 日
You have not used contour in the above code. First, is the above code running ? Is it showing the error ypu have mentioned?
Chinwendu Madubueze
Chinwendu Madubueze 2020 年 5 月 28 日
編集済み: Adam Danz 2020 年 5 月 28 日
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')
Adam Danz
Adam Danz 2020 年 5 月 28 日
The code above works for me in r2020a.
What version of Matlab are you using?
John D'Errico
John D'Errico 2020 年 5 月 28 日
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.
Chinwendu Madubueze
Chinwendu Madubueze 2020 年 5 月 28 日
Adam Danz. I am using the R2007b version.
Chinwendu Madubueze
Chinwendu Madubueze 2020 年 5 月 28 日
John D'Errico thank you for your responses. I named the script, contour plot.
John D'Errico
John D'Errico 2020 年 5 月 28 日
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.
Chinwendu Madubueze
Chinwendu Madubueze 2020 年 5 月 28 日
編集済み: Chinwendu Madubueze 2020 年 5 月 28 日
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeContour Plots についてさらに検索

質問済み:

2020 年 5 月 28 日

編集済み:

2020 年 5 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by