Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: greater than or less than

Subject: greater than or less than

From: Ender

Date: 30 Aug, 2007 05:03:13

Message: 1 of 10

I am writing a program that is going to plot a function. I
don't know the correct way to write a matlab function that
will: 10<=x<=1.2*y (1)

y=3.2

Whenever I type in the code as is, MatLab wants me to
define x. I am going to put x in another function, ex
2.7+x=t. I am going to plot x vs. t. I just don't know how
to tell MatLab to take values in between the range of the
above stated values in equation (1).

Subject: greater than or less than

From: "elbocata@gmail.com

Date: 30 Aug, 2007 09:36:11

Message: 2 of 10

On 30 ago, 07:03, "Ender " <jr...@msstate.edu> wrote:
> I am writing a program that is going to plot a function. I
> don't know the correct way to write a matlab function that
> will: 10<=x<=1.2*y (1)
>
> y=3.2
>
> Whenever I type in the code as is, MatLab wants me to
> define x. I am going to put x in another function, ex
> 2.7+x=t. I am going to plot x vs. t. I just don't know how
> to tell MatLab to take values in between the range of the
> above stated values in equation (1).

If y=3.2, x cannot be both greater than 10 and less than 1.2*3.2, can
it?????

Subject: greater than or less than

From: Loren Shure

Date: 30 Aug, 2007 12:25:25

Message: 3 of 10

In article <fb5j2h$2n2$1@fred.mathworks.com>, jr147@msstate.edu says...
> I am writing a program that is going to plot a function. I
> don't know the correct way to write a matlab function that
> will: 10<=x<=1.2*y (1)
>
> y=3.2
>
> Whenever I type in the code as is, MatLab wants me to
> define x. I am going to put x in another function, ex
> 2.7+x=t. I am going to plot x vs. t. I just don't know how
> to tell MatLab to take values in between the range of the
> above stated values in equation (1).
>

Perhaps an anonymous function will help... It requires that y be
defined in advance, but not x.

between = @(x) (x >= 10) & (x < 1.2*y)

then use

x = 1:20
out = between(x)
and you will get a logical vector saying where the conditions are true
and not.

--
Loren
http://blogs.mathworks.com/loren/

Subject: greater than or less than

From: Ender

Date: 30 Aug, 2007 18:00:00

Message: 4 of 10

Loren Shure <loren@mathworks.com> wrote in message
<MPG.214081424ffda7f9897ad@news.mathworks.com>...
> In article <fb5j2h$2n2$1@fred.mathworks.com>,
jr147@msstate.edu says...
> > I am writing a program that is going to plot a
function. I
> > don't know the correct way to write a matlab function
that
> > will: 10<=x<=1.2*y (1)
> >
> > y=3.2
> >
> > Whenever I type in the code as is, MatLab wants me to
> > define x. I am going to put x in another function, ex
> > 2.7+x=t. I am going to plot x vs. t. I just don't know
how
> > to tell MatLab to take values in between the range of
the
> > above stated values in equation (1).
> >
>
> Perhaps an anonymous function will help... It requires
that y be
> defined in advance, but not x.
>
> between = @(x) (x >= 10) & (x < 1.2*y)
>
> then use
>
> x = 1:20
> out = between(x)
> and you will get a logical vector saying where the
conditions are true
> and not.
>
> --
> Loren
> http://blogs.mathworks.com/loren/


"x=1:20"

Does this code mean that MatLab is taken values for x at
20 equal increments?

Subject: greater than or less than

From: dpb

Date: 30 Aug, 2007 18:07:04

Message: 5 of 10

Ender wrote:
...
> "x=1:20"
>
> Does this code mean that MatLab is taken values for x at
> 20 equal increments?

help colon

Subject: greater than or less than

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 30 Aug, 2007 18:14:32

Message: 6 of 10

In article <fb70j0$mr6$1@fred.mathworks.com>, Ender <jr147@msstate.edu> wrote:

>"x=1:20"

>Does this code mean that MatLab is taken values for x at
>20 equal increments?

No, it means that x is taken to be the vector containing the
numbers 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

x=1:3:20

would be [1 4 7 10 13 16 19]

that is, if you have X:Y then you get a vector containing
X X+1 X+2 X+3 and so on with the last element being the
greatest X+integer that is less than or equal to Y;

if you have X:S:Y then you get a vector containing
X X+S X+2*S X+3*S X+4*S and so on with the last element
being the greatest X+S*integer that is less than or equal to Y.

--
  If you lie to the compiler, it will get its revenge. -- Henry Spencer

Subject: greater than or less than

From: Scott Seidman

Date: 30 Aug, 2007 18:18:22

Message: 7 of 10

"Ender " <jr147@msstate.edu> wrote in news:fb5j2h$2n2$1@fred.mathworks.com:

> I am writing a program that is going to plot a function. I
> don't know the correct way to write a matlab function that
> will: 10<=x<=1.2*y (1)
>
> y=3.2
>
> Whenever I type in the code as is, MatLab wants me to
> define x. I am going to put x in another function, ex
> 2.7+x=t. I am going to plot x vs. t. I just don't know how
> to tell MatLab to take values in between the range of the
> above stated values in equation (1).


You should really read the Getting Started section.


--
Scott
Reverse name to reply

Subject: greater than or less than

From: Loren Shure

Date: 30 Aug, 2007 20:51:55

Message: 8 of 10

In article <fb70j0$mr6$1@fred.mathworks.com>, jr147@msstate.edu says...
> Loren Shure <loren@mathworks.com> wrote in message
> <MPG.214081424ffda7f9897ad@news.mathworks.com>...
> > In article <fb5j2h$2n2$1@fred.mathworks.com>,
> jr147@msstate.edu says...
> > > I am writing a program that is going to plot a
> function. I
> > > don't know the correct way to write a matlab function
> that
> > > will: 10<=x<=1.2*y (1)
> > >
> > > y=3.2
> > >
> > > Whenever I type in the code as is, MatLab wants me to
> > > define x. I am going to put x in another function, ex
> > > 2.7+x=t. I am going to plot x vs. t. I just don't know
> how
> > > to tell MatLab to take values in between the range of
> the
> > > above stated values in equation (1).
> > >
> >
> > Perhaps an anonymous function will help... It requires
> that y be
> > defined in advance, but not x.
> >
> > between = @(x) (x >= 10) & (x < 1.2*y)
> >
> > then use
> >
> > x = 1:20
> > out = between(x)
> > and you will get a logical vector saying where the
> conditions are true
> > and not.
> >
> > --
> > Loren
> > http://blogs.mathworks.com/loren/
>
>
> "x=1:20"
>
> Does this code mean that MatLab is taken values for x at
> 20 equal increments?
>
>

Yes. Perhaps you'd find it valuable to read the Getting Started section
of the documentation:

http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/bqr_
2pl.html


--
Loren
http://blogs.mathworks.com/loren/

Subject: greater than or less than

From: Ender

Date: 31 Aug, 2007 21:07:20

Message: 9 of 10

Loren Shure <loren@mathworks.com> wrote in message
<MPG.2140d13018f6f7989897af@news.mathworks.com>...
> In article <fb70j0$mr6$1@fred.mathworks.com>,
jr147@msstate.edu says...
> > Loren Shure <loren@mathworks.com> wrote in message
> > <MPG.214081424ffda7f9897ad@news.mathworks.com>...
> > > In article <fb5j2h$2n2$1@fred.mathworks.com>,
> > jr147@msstate.edu says...
> > > > I am writing a program that is going to plot a
> > function. I
> > > > don't know the correct way to write a matlab
function
> > that
> > > > will: 10<=x<=1.2*y (1)
> > > >
> > > > y=3.2
> > > >
> > > > Whenever I type in the code as is, MatLab wants me
to
> > > > define x. I am going to put x in another function,
ex
> > > > 2.7+x=t. I am going to plot x vs. t. I just don't
know
> > how
> > > > to tell MatLab to take values in between the range
of
> > the
> > > > above stated values in equation (1).
> > > >
> > >
> > > Perhaps an anonymous function will help... It
requires
> > that y be
> > > defined in advance, but not x.
> > >
> > > between = @(x) (x >= 10) & (x < 1.2*y)
> > >
> > > then use
> > >
> > > x = 1:20
> > > out = between(x)
> > > and you will get a logical vector saying where the
> > conditions are true
> > > and not.
> > >
> > > --
> > > Loren
> > > http://blogs.mathworks.com/loren/
> >
> >
> > "x=1:20"
> >
> > Does this code mean that MatLab is taken values for x
at
> > 20 equal increments?
> >
> >
>
> Yes. Perhaps you'd find it valuable to read the Getting
Started section
> of the documentation:
>
>
http://www.mathworks.com/access/helpdesk/help/techdoc/learn
_matlab/bqr_
> 2pl.html
>
>
> --
> Loren
> http://blogs.mathworks.com/loren/


I tried to access the getting started section but the page
didn't display.
I have a question and maybe I didn't phrase what I wanted
properly. I am trying to take values from 10<=x<=46.75 I
want to make an (i) iteration loop that will take values
at specified increments between 10 and 30. I plan on
stating x(i) within this loop. How do I do this?

I tried to accomplish the above stated task this way, but
it didn't work. I wrote code that looked vary similiar to
this

for i=10:1:46.75
    x(i)=10*i
    y(i)=3+x(i)
end

I then plotted a graph in Excel to show my results.
Whenever I try to change the "1" to "0.001" to get a more
refined value in my graph. MatLab gave me this answer.

??? Attempted to access sig_AL_cr(0.001); index must be a
positive integer or logical

I don't know why?
    

Subject: greater than or less than

From: Peter Boettcher

Date: 31 Aug, 2007 21:23:18

Message: 10 of 10

"Ender " <jr147@msstate.edu> writes:

> I tried to access the getting started section but the page
> didn't display.
> I have a question and maybe I didn't phrase what I wanted
> properly. I am trying to take values from 10<=x<=46.75 I
> want to make an (i) iteration loop that will take values
> at specified increments between 10 and 30. I plan on
> stating x(i) within this loop. How do I do this?
>
> I tried to accomplish the above stated task this way, but
> it didn't work. I wrote code that looked vary similiar to
> this
>
> for i=10:1:46.75
> x(i)=10*i
> y(i)=3+x(i)
> end
>
> I then plotted a graph in Excel to show my results.
> Whenever I try to change the "1" to "0.001" to get a more
> refined value in my graph. MatLab gave me this answer.
>
> ??? Attempted to access sig_AL_cr(0.001); index must be a
> positive integer or logical

Ah. That's a well-phrased question.

x(i) is an array reference. i is an index. An index has to be an
integer > 0. (What is the 0.5 number in an array?)

A common coding pattern for what you want is this:

x = 10:.001:46.75;

for i=1:length(x)
  y(i) = 3 + 10*x(i);
end

Of course, this is MATLAB, so you can compute simple operations like
that without a loop.

x = 10:.001:46.75;
y = 3 + 10.*x;

And you REALLY need to read the Getting Started section. I guess
Loren's URL was wrapped (thanks to the brand new Forum software).
Just go to the main MATLAB documentation page and click to Getting
Started.

http://www.mathworks.com/access/helpdesk/help/techdoc/


-Peter

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
iteration Ender 31 Aug, 2007 17:10:07
range Ender 30 Aug, 2007 01:05:05
greater than Ender 30 Aug, 2007 01:05:05
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics