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:
iteration to vector

Subject: iteration to vector

From: Chris

Date: 19 Feb, 2010 09:04:04

Message: 1 of 5

ok this is really frustrating...
I want each iteration of n to be in the same vector
I have:

input = 200;
n = input;
while n > 38
    n = round(n ./3 + 25);
    disp(n) %shows the iterations of n
end
end

When I do this it shows the iterations of n but I cannot do anything with them
I tried:

vec = disp(k) but it comes up with an error.

I looked on the forums and it seems like I need a for loop.
Any help?

Subject: iteration to vector

From: Jan Simon

Date: 19 Feb, 2010 22:13:04

Message: 2 of 5

Dear Chris!

> I want each iteration of n to be in the same vector
>
> input = 200;
> n = input;
> while n > 38
> n = round(n ./3 + 25);
> disp(n) %shows the iterations of n
> end
> end
>
> When I do this it shows the iterations of n but I cannot do anything with them
> I tried:
> vec = disp(k) but it comes up with an error.
>
> I looked on the forums and it seems like I need a for loop.
> Any help?

Yes, any help.
Define the meaning of "I want each iteration of n to be in the same vector" exactly.
What do you expect "vec = disp(k)" to do? What is k ?!

Good luck, Jan

Subject: iteration to vector

From: Nathan

Date: 19 Feb, 2010 22:23:22

Message: 3 of 5

On Feb 19, 1:04 am, "Chris " <ridered30...@hotmail.com> wrote:
> ok this is really frustrating...
> I want each iteration of n to be in the same vector
> I have:
>
> input = 200;
> n = input;
> while n > 38
>     n = round(n ./3 + 25);
>     disp(n) %shows the iterations of n
> end
> end
>
> When I do this it shows the iterations of n but I cannot do anything with them
> I tried:
>
> vec = disp(k) but it comes up with an error.
>
> I looked on the forums and it seems like I need a for loop.
> Any help?

So, n = 200. 200 is not a vector. It is a single value.
How do you expect to find a vector if you are only using a single
value?

If you want each changed value of n to be contained within a vector,
you could so something along the lines of:

input = 200;
n = input;
ii = 2;
nlimit = 38;
vec = zeros(1,25-floor(exp(3))+1);
vec(1) = n;
while n > nlimit
    n = round(n ./3 + 25);
    disp(n) %shows the iterations of n
    vec(ii) = n;
    ii = ii + 1;
end

%%%%%%

vec =

   200 92 56 44 40 38

If this isn't what you want, be more precise (please).

-Nathan

Subject: iteration to vector

From: Sadik

Date: 20 Feb, 2010 00:55:06

Message: 4 of 5

Plus, you should use num2str to display a number. Please replace

disp(n);

with

disp(num2str(n));

Best.



Nathan <ngreco32@gmail.com> wrote in message <d733956c-58db-4150-8bbc-fc1dfc6cb9ab@p13g2000pre.googlegroups.com>...
> On Feb 19, 1:04 am, "Chris " <ridered30...@hotmail.com> wrote:
> > ok this is really frustrating...
> > I want each iteration of n to be in the same vector
> > I have:
> >
> > input = 200;
> > n = input;
> > while n > 38
> >     n = round(n ./3 + 25);
> >     disp(n) %shows the iterations of n
> > end
> > end
> >
> > When I do this it shows the iterations of n but I cannot do anything with them
> > I tried:
> >
> > vec = disp(k) but it comes up with an error.
> >
> > I looked on the forums and it seems like I need a for loop.
> > Any help?
>
> So, n = 200. 200 is not a vector. It is a single value.
> How do you expect to find a vector if you are only using a single
> value?
>
> If you want each changed value of n to be contained within a vector,
> you could so something along the lines of:
>
> input = 200;
> n = input;
> ii = 2;
> nlimit = 38;
> vec = zeros(1,25-floor(exp(3))+1);
> vec(1) = n;
> while n > nlimit
> n = round(n ./3 + 25);
> disp(n) %shows the iterations of n
> vec(ii) = n;
> ii = ii + 1;
> end
>
> %%%%%%
>
> vec =
>
> 200 92 56 44 40 38
>
> If this isn't what you want, be more precise (please).
>
> -Nathan

Subject: iteration to vector

From: us

Date: 20 Feb, 2010 07:15:21

Message: 5 of 5

"Sadik " <sadik.hava@gmail.com> wrote in message <hlnbta$6fi$1@fred.mathworks.com>...
> Plus, you should use num2str to display a number. Please replace
> disp(n);
> with
> disp(num2str(n));
> Best.

why(?)...

us

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