From: Vishal P on
hello there,

I want to plot graph of T vs U where T ranges from 0 to 5 with increment of 0.5 and error i get is

??? Subscript indices must either be real positive integers or
logicals.

Error in ==> Modeling at 98
x(imax) = 0:0.5:5;

code is

T = 5; % Injection time in ms %
deltaT = 0.5; % Computational time step in ms %
imax = 0:0.5:T;


for i = 1:length(imax)
x(imax) = 0:0.5:5;
M(i) = Cd*An*sqrt(2*Rho1*Pdrop); % Mass flow rate through each nozzle %
U(i) = Cd*sqrt(2*Pdrop/Rho1); %Fuel injection velocity at nozzle tip %
end

figure(1)
plot(x,U)
hold on
plot (x,M,'r')



if any1 can help please do....as i am just learning matlab....thanks
From: Andy on
"Vishal P" <vishalparmar06(a)yahoo.co.uk> wrote in message <i43dqh$3mq$1(a)fred.mathworks.com>...
> hello there,
>
> I want to plot graph of T vs U where T ranges from 0 to 5 with increment of 0.5 and error i get is
>
> ??? Subscript indices must either be real positive integers or
> logicals.
>
> Error in ==> Modeling at 98
> x(imax) = 0:0.5:5;
>
> code is
>
> T = 5; % Injection time in ms %
> deltaT = 0.5; % Computational time step in ms %
> imax = 0:0.5:T;
>
>
> for i = 1:length(imax)
> x(imax) = 0:0.5:5;
> M(i) = Cd*An*sqrt(2*Rho1*Pdrop); % Mass flow rate through each nozzle %
> U(i) = Cd*sqrt(2*Pdrop/Rho1); %Fuel injection velocity at nozzle tip %
> end
>
> figure(1)
> plot(x,U)
> hold on
> plot (x,M,'r')
>
>
>
> if any1 can help please do....as i am just learning matlab....thanks

Well, the error message is clear. The variable imax is 0:0.5:T. So, for example, it contains the number 0.5. You then try to use 0.5 as an index into x:

x(imax)

which returns the error. You can't look at the 0.5th element of a vector.
From: Vishal P on
"Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i43eh1$hml$1(a)fred.mathworks.com>...
> "Vishal P" <vishalparmar06(a)yahoo.co.uk> wrote in message <i43dqh$3mq$1(a)fred.mathworks.com>...
> > hello there,
> >
> > I want to plot graph of T vs U where T ranges from 0 to 5 with increment of 0.5 and error i get is
> >
> > ??? Subscript indices must either be real positive integers or
> > logicals.
> >
> > Error in ==> Modeling at 98
> > x(imax) = 0:0.5:5;
> >
> > code is
> >
> > T = 5; % Injection time in ms %
> > deltaT = 0.5; % Computational time step in ms %
> > imax = 0:0.5:T;
> >
> >
> > for i = 1:length(imax)
> > x(imax) = 0:0.5:5;
> > M(i) = Cd*An*sqrt(2*Rho1*Pdrop); % Mass flow rate through each nozzle %
> > U(i) = Cd*sqrt(2*Pdrop/Rho1); %Fuel injection velocity at nozzle tip %
> > end
> >
> > figure(1)
> > plot(x,U)
> > hold on
> > plot (x,M,'r')
> >
> >
> >
> > if any1 can help please do....as i am just learning matlab....thanks
>
> Well, the error message is clear. The variable imax is 0:0.5:T. So, for example, it contains the number 0.5. You then try to use 0.5 as an index into x:
>
> x(imax)
>
> which returns the error. You can't look at the 0.5th element of a vector.


As u said I did this....and found same error

Subscript indices must either be real positive integers or
logicals.

Error in ==> Modeling at 98
x(imax) = 0.5:0.5:5;
for i = 1:length(imax)
x(imax) = 0.5:0.5:5;
M(i) = Cd*An*sqrt(2*Rho1*Pdrop); % Mass flow rate through each nozzle %
U(i) = Cd*sqrt(2*Pdrop/Rho1); %Fuel injection velocity at nozzle tip %
end


thnks for ur reply....hope u can help me again
From: Walter Roberson on
Vishal P wrote:
> hello there,
>
> I want to plot graph of T vs U where T ranges from 0 to 5 with increment
> of 0.5 and error i get is
> ??? Subscript indices must either be real positive integers or
> logicals.
>
> Error in ==> Modeling at 98
> x(imax) = 0:0.5:5;
>
> code is
> T = 5; % Injection time in ms %
> deltaT = 0.5; % Computational time step in ms %
> imax = 0:0.5:T;

There you set imax to a vector of numbers, [0, 0.5, 1, 1.5] and so on to 5.


> for i = 1:length(imax)
> x(imax) = 0:0.5:5;

There you try to use the complete vector of numbers as a list of
subscripts to x, and you try to assign a vector of numbers to the
locations indicated. So you try to assign 0 to x(0), try to assign 0.5
to x(0.5) and so on. Subscripts must, however, be positive integers such
as 1, 2, 3, 4, 5, 6, ... and so Matlab doesn't know what you mean.

What do you perceive that you are trying to accomplish what that
statement? Does it differ from what you would accomplish by using

x = imax;


> M(i) = Cd*An*sqrt(2*Rho1*Pdrop); % Mass flow rate through each nozzle %
> U(i) = Cd*sqrt(2*Pdrop/Rho1); %Fuel injection velocity at nozzle
> tip %
> end
>
> figure(1)
> plot(x,U)
> hold on plot (x,M,'r')
>
>
>
> if any1 can help please do....as i am just learning matlab....thanks
From: Steven_Lord on


"Vishal P" <vishalparmar06(a)yahoo.co.uk> wrote in message
news:i43f3p$oin$1(a)fred.mathworks.com...
> "Andy " <myfakeemailaddress(a)gmail.com> wrote in message
> <i43eh1$hml$1(a)fred.mathworks.com>...
>> "Vishal P" <vishalparmar06(a)yahoo.co.uk> wrote in message
>> <i43dqh$3mq$1(a)fred.mathworks.com>...

*snip*

> As u said I did this....and found same error
>
> Subscript indices must either be real positive integers or
> logicals.
>
> Error in ==> Modeling at 98
> x(imax) = 0.5:0.5:5;
> for i = 1:length(imax)
> x(imax) = 0.5:0.5:5;
> M(i) = Cd*An*sqrt(2*Rho1*Pdrop); % Mass flow rate through each nozzle
> %
> U(i) = Cd*sqrt(2*Pdrop/Rho1); %Fuel injection velocity at nozzle
> tip %
> end
>
>
> thnks for ur reply....hope u can help me again

There is no such thing as the 0.5th element of a vector. Therefore because
imax contains the value 0.5, it CANNOT be used as an index into a variable
directly. x(imax) will NEVER work for this imax vector. Period, end of
story.

You need to find something else that only takes on positive integer values
to use as your indices. You have a suitable index variable in the code I
left unsnipped from your message; in fact, you even use that variable as an
index variable in that section of code.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com