I have been faced with the 'Index exceeds array bounds' while graphing.

Hey, I am trying to use the for code to plot a graph and it keeps saying that my index exceeds the array bounds. Not sure what to do to correct the loop. Thank you in advance.
Tr=0.85:0.05:1;
MV= 0.15:0.02:1.75
Pr=zeros(length(Tr),81);
Tr=0.85:0.05:1;
for i= 1:length(Tr)
i
MV= 0.15:0.02:1.75;
[Pr(i,:)] = Isotherm(Tr(i));
hplot=semilogy(MV,Pr(i,:),'-')
hold on
set(hplot(i),'color', 'red', 'Marker','o')
set(hplot(i),'color', 'cyan')
set(hplot(i),'color', 'magenta')
set(hplot(i),'color', 'blue')
set(hplot,'linewidth', 1)
end

6 Comments

it is at a different constant temperature for each time the iteration runs. so all that is changing is the molar volume and pressure.
also that is just what I named my generic function.
function [Pr] = Isotherm(Tr)
MV= 0.15:0.02:1.75 %Range of molar volumes provided by the Brief.
Pr= ((8*(Tr))./((8*(MV)) - 1) - (27./(64*(MV.^2))));
end
You can’t index a floating number to a variable
Sorry not sure which is the floating number, new to MATLAB. Do you mind explaining what you mean by that.
Also what would you suggest I should use to plot the graphs of the 4 different graphs to produce lines of different colors and markers. Thank you for your help.

Sign in to comment.

 Accepted Answer

Tr=0.85:0.05:1;
MV= 0.15:0.02:1.75
Pr=zeros(length(Tr),81);
Tr=0.85:0.05:1;
MV= 0.15:0.02:1.75;
%Range of molar volumes provided by the Brief.
Pr=cell(1,4)
for i = 1:numel(Tr)
Pr{i}= ((8.*(Tr(i)))./((8.*(MV)) - 1) - (27./(64.*(MV.^2))));
end;
hplot=semilogy(MV,Pr{1},'-')
hold on
hplot1=semilogy(MV,Pr{2},'-')
hplot2=semilogy(MV,Pr{3},'-')
hplot3=semilogy(MV,Pr{4},'-')
set(hplot,'color', 'red', 'Marker','o')
set(hplot1,'color', 'cyan')
set(hplot2,'color', 'magenta')
set(hplot3,'color', 'blue')

More Answers (0)

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!