Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
matlab variable

Subject: matlab variable

From: zafar khan

Date: 8 Nov, 2010 18:13:04

Message: 1 of 10

Hi Dear
i want to assign following values to a variable " x ";
 vaues : 1<x<4

how can i assign these values to the variable x in matlab ??????????

Subject: matlab variable

From: ImageAnalyst

Date: 8 Nov, 2010 18:21:00

Message: 2 of 10

What values? The infinite number of values in between 1 and 4?

Subject: matlab variable

From: Sean

Date: 8 Nov, 2010 18:21:04

Message: 3 of 10

"zafar khan" <zafarmammak@gmail.com> wrote in message <ib9ejg$90t$1@fred.mathworks.com>...
> Hi Dear
> i want to assign following values to a variable " x ";
> vaues : 1<x<4
>
> how can i assign these values to the variable x in matlab ??????????

x = 1:4 %increment by 1
x = 1:increment:4; %where increment is the spacing (e.g. 0.1 or 0.2)

Subject: matlab variable

From: zafar khan

Date: 8 Nov, 2010 18:29:07

Message: 4 of 10

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <cd9fdf9b-7b21-4aaf-8653-6ae20ad35c4f@42g2000prt.googlegroups.com>...
> What values? The infinite number of values in between 1 and 4?

with increment of .01 but end points of interval i.e., 1 & 4 not the value of x.
then?????

Subject: matlab variable

From: Walter Roberson

Date: 8 Nov, 2010 18:45:16

Message: 5 of 10

On 10-11-08 12:29 PM, zafar khan wrote:
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> <cd9fdf9b-7b21-4aaf-8653-6ae20ad35c4f@42g2000prt.googlegroups.com>...
>> What values? The infinite number of values in between 1 and 4?
>
> with increment of .01 but end points of interval i.e., 1 & 4 not the
> value of x.
> then?????

So use [1:.01:4] and then throw away the first and last values.

Subject: matlab variable

From: zafar khan

Date: 22 Nov, 2010 13:14:04

Message: 6 of 10

Walter Roberson <roberson@hushmail.com> wrote in message <ib9gft$5id$2@canopus.cc.umanitoba.ca>...
> On 10-11-08 12:29 PM, zafar khan wrote:
> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> > <cd9fdf9b-7b21-4aaf-8653-6ae20ad35c4f@42g2000prt.googlegroups.com>...
> >> What values? The infinite number of values in between 1 and 4?
> >
> > with increment of .01 but end points of interval i.e., 1 & 4 not the
> > value of x.
> > then?????
>
> So use [1:.01:4] and then throw away the first and last values.

dear Sir! how can i throw end values

Subject: matlab variable

From: Walter Roberson

Date: 22 Nov, 2010 17:59:55

Message: 7 of 10

On 22/11/10 7:14 AM, zafar khan wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
> <ib9gft$5id$2@canopus.cc.umanitoba.ca>...
>> On 10-11-08 12:29 PM, zafar khan wrote:
>> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message
>> > <cd9fdf9b-7b21-4aaf-8653-6ae20ad35c4f@42g2000prt.googlegroups.com>...
>> >> What values? The infinite number of values in between 1 and 4?
>> >
>> > with increment of .01 but end points of interval i.e., 1 & 4 not the
>> > value of x.
>> > then?????
>>
>> So use [1:.01:4] and then throw away the first and last values.
>
> dear Sir! how can i throw end values

x = 1:.01:4;
x = x(2:end-1); %throw away first and last point

Subject: matlab variable

From: zafar khan

Date: 11 Dec, 2010 12:33:04

Message: 8 of 10

Walter Roberson <roberson@hushmail.com> wrote in message <vcyGo.52787$Mk2.12983@newsfe13.iad>...
> On 22/11/10 7:14 AM, zafar khan wrote:
> > Walter Roberson <roberson@hushmail.com> wrote in message
> > <ib9gft$5id$2@canopus.cc.umanitoba.ca>...
> >> On 10-11-08 12:29 PM, zafar khan wrote:
> >> > ImageAnalyst <imageanalyst@mailinator.com> wrote in message
> >> > <cd9fdf9b-7b21-4aaf-8653-6ae20ad35c4f@42g2000prt.googlegroups.com>...
> >> >> What values? The infinite number of values in between 1 and 4?
> >> >
> >> > with increment of .01 but end points of interval i.e., 1 & 4 not the
> >> > value of x.
> >> > then?????
> >>
> >> So use [1:.01:4] and then throw away the first and last values.
> >
> > dear Sir! how can i throw end values
>
> x = 1:.01:4;
> x = x(2:end-1); %throw away first and last point
Thanks a lot

Subject: matlab variable

From: Paulo Silva

Date: 11 Dec, 2010 13:58:04

Message: 9 of 10

another solution:

increment=0.01;
first=1;last=4;
x = first+increment:increment:last-increment;

Subject: matlab variable

From: Walter Roberson

Date: 11 Dec, 2010 16:13:40

Message: 10 of 10

On 11/12/10 7:58 AM, Paulo Silva wrote:
> another solution:
>
> increment=0.01;
> first=1;last=4;
> x = first+increment:increment:last-increment;

Unfortunately due to floating point precision issues, since the
increment is not exactly representable in floating point numbers, the
results would not come out exactly the same as using
first:increment:last and discarding the first and last points.

x = first+increment:increment:last-increment;
x2 = first:increment:last; x2 = x2(2:end-1);
 >> find(x-x2)
ans =
   Columns 1 through 13
     36 84 151 152 155 156 160 161 164 165 168
169 172
[and so on to 74 differences]
 >> x(36)-x2(36)
ans =
       2.22044604925031e-16

Tags for this Thread

No tags are associated with this thread.

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.

Contact us