From: chris c Colose on
I am trying to plot a line which behaves differently depending on the value of the independent variable. For values of T (on the x-axis) less than T0 I want a constant value a=0.6, for values of T greater than T1 I want a constant value a=0.2. For T between 263 and 283 I want the function shown in the program. When I run my program the last function dominates for all values of T, not just over the interval 263 to 283. What do I do with this?

My command is

T0=263;
T1=283;
a1=0.2;
a0=0.6;

T = 150:1:350
if T < T0
a = a0;

elseif T > T1
a = a1;

else
a= a0+ (((T-T0)/(T1-T0))*(a1-a0));

end
plot(T,a)
From: Walter Roberson on
chris c Colose wrote:
> I am trying to plot a line which behaves differently depending on the
> value of the independent variable. For values of T (on the x-axis) less
> than T0 I want a constant value a=0.6, for values of T greater than T1 I
> want a constant value a=0.2. For T between 263 and 283 I want the
> function shown in the program. When I run my program the last function
> dominates for all values of T, not just over the interval 263 to 283.
> What do I do with this?
>
> My command is
>
> T0=263;
> T1=283;
> a1=0.2;
> a0=0.6;
>
> T = 150:1:350
> if T < T0
> a = a0;
>
> elseif T > T1
> a = a1;
>
> else
> a= a0+ (((T-T0)/(T1-T0))*(a1-a0));
> end
> plot(T,a)

You have created T as a vector of values. When you test

if T < T0

then that is equivalent to testing

if all(T < T0)

which is probably false. Likewise, the test T > T1 would be all(T > T1) which
is probably false as well. You would thus fall through to the last case.

I suggest you start with:

T = 150:1:350
a = zeros(size(T));
a(T < T0) = a0;
a(T > T1) = a1;

and I leave it as an exercise for you to figure out how to handle the other
possibility.
From: us on
"chris c Colose" <chrisc31621(a)yahoo.com> wrote in message <i3cv1u$3r4$1(a)fred.mathworks.com>...
> I am trying to plot a line which behaves differently depending on the value of the independent variable. For values of T (on the x-axis) less than T0 I want a constant value a=0.6, for values of T greater than T1 I want a constant value a=0.2. For T between 263 and 283 I want the function shown in the program. When I run my program the last function dominates for all values of T, not just over the interval 263 to 283. What do I do with this?
>
> My command is
>
> T0=263;
> T1=283;
> a1=0.2;
> a0=0.6;
>
> T = 150:1:350
> if T < T0
> a = a0;
>
> elseif T > T1
> a = a1;
>
> else
> a= a0+ (((T-T0)/(T1-T0))*(a1-a0));
>
> end
> plot(T,a)

one of the many solutions
- use logical indexing

T0=263;
T1=283;
a1=0.2;
a0=0.6;
T=150:1:350;
a=nan(size(T));
a(T<T0)=a0;
a(T>T1)=a1;
b=a0+(((T-T0)/(T1-T0))*(a1-a0));
a(isnan(a))=b(isnan(a));
plot(T,a,'-k.');

us