Thread Subject: cellarray

Subject: cellarray

From: furla furr

Date: 30 May, 2011 17:28:06

Message: 1 of 10

Hi There!

I have an enquiry on cellarray(beginner level). Let say I have this matrix :

globalarry=
[0 2 0 3 4
 0 1 2 0 0
 0 1 2 0 4
 1 2 0 0 3
 1 0 0 0 4
 2 2 0 3 4
 0 1 2 0 0
 0 1 2 0 4
 1 2 0 0 3
 1 3 0 0 4
 0 2 0 3 4
 0 1 2 0 0
 0 1 2 0 4
 1 2 0 0 3
 1 0 0 0 4];

The matrix above is from 5x5 grids and resulted from from three times iteration. '1':Left,'2':Right,'3':Up and '4':Down pedestrians. '0': empty cell
How do I update the new matrix (which starts off with all zeros) so that if the pedestrian could not move in their intended direction , the position the pedestrian was in is increased by one.

I did try to convert the above matrix to cellarray. But then, I stuck when I want to update every element in cellarray with the rules mention above.
Please guide.

Thanks,
Furla

Subject: cellarray

From: Wayne King

Date: 30 May, 2011 19:15:05

Message: 2 of 10

"furla furr" wrote in message <is0k36$32o$1@newscl01ah.mathworks.com>...
> Hi There!
>
> I have an enquiry on cellarray(beginner level). Let say I have this matrix :
>
> globalarry=
> [0 2 0 3 4
> 0 1 2 0 0
> 0 1 2 0 4
> 1 2 0 0 3
> 1 0 0 0 4
> 2 2 0 3 4
> 0 1 2 0 0
> 0 1 2 0 4
> 1 2 0 0 3
> 1 3 0 0 4
> 0 2 0 3 4
> 0 1 2 0 0
> 0 1 2 0 4
> 1 2 0 0 3
> 1 0 0 0 4];
>
> The matrix above is from 5x5 grids and resulted from from three times iteration. '1':Left,'2':Right,'3':Up and '4':Down pedestrians. '0': empty cell
> How do I update the new matrix (which starts off with all zeros) so that if the pedestrian could not move in their intended direction , the position the pedestrian was in is increased by one.
>
> I did try to convert the above matrix to cellarray. But then, I stuck when I want to update every element in cellarray with the rules mention above.
> Please guide.
>
> Thanks,
> Furla

Hi Furla, I don't understand exactly what you are trying to do with the above, but have you looked at the help for cellfun(), or arrayfun().

Wayne

Subject: cellarray

From: furla furr

Date: 30 May, 2011 19:41:04

Message: 3 of 10

Hi Wayne,

Thank you for reply.

I want to compare the ri element with the next ri+25. for the left case, if ri =1, and ri+25-1 not equal to one, then, ri in zeros heatmap(5x5) will update to one. for right case, if ri=2, and ri+25+1 not equal to one, then, ri in zeros heatmap(5x5) will update to one also. and same goes to up and down case.

Hope that I have give clearer explanation. I will have a look on cellfun(), or arrayfun() also.

Many thanks,
Furla

 
"Wayne King" <wmkingty@gmail.com> wrote in message <is0qbp$hdk$1@newscl01ah.mathworks.com>...
> "furla furr" wrote in message <is0k36$32o$1@newscl01ah.mathworks.com>...
> > Hi There!
> >
> > I have an enquiry on cellarray(beginner level). Let say I have this matrix :
> >
> > globalarry=
> > [0 2 0 3 4
> > 0 1 2 0 0
> > 0 1 2 0 4
> > 1 2 0 0 3
> > 1 0 0 0 4
> > 2 2 0 3 4
> > 0 1 2 0 0
> > 0 1 2 0 4
> > 1 2 0 0 3
> > 1 3 0 0 4
> > 0 2 0 3 4
> > 0 1 2 0 0
> > 0 1 2 0 4
> > 1 2 0 0 3
> > 1 0 0 0 4];
> >
> > The matrix above is from 5x5 grids and resulted from from three times iteration. '1':Left,'2':Right,'3':Up and '4':Down pedestrians. '0': empty cell
> > How do I update the new matrix (which starts off with all zeros) so that if the pedestrian could not move in their intended direction , the position the pedestrian was in is increased by one.
> >
> > I did try to convert the above matrix to cellarray. But then, I stuck when I want to update every element in cellarray with the rules mention above.
> > Please guide.
> >
> > Thanks,
> > Furla
>
> Hi Furla, I don't understand exactly what you are trying to do with the above, but have you looked at the help for cellfun(), or arrayfun().
>
> Wayne

Subject: cellarray

From: ImageAnalyst

Date: 30 May, 2011 21:40:46

Message: 4 of 10

On May 30, 3:41 pm, "furla furr" <furlaf...@yahoo.com> wrote:
> Hope that I have give clearer explanation.
--------------------------------------------------
Nope, didn't do it for me. All I could figure out is that you're
trying to do some kind of simulation with pedestrians walking on a
grid, and that there are some conditions where certain elements will
get set to 1.

But if you're looking at the (ri)th element, say (row=3, column = 2),
where exactly is the (ri+25-1)th element? What row and column would
that be in? And then do you just scan the grid as ri goes from 1 to
numel(globalarry) and check the (ri+25-1) the element? What happens
when that element if past the end of the array, for example when
ri>numel(globalarry)-24? In that case (ri+25-1) will be greater than
the number of elements in globalarry.

Subject: cellarray

From: furla furr

Date: 30 May, 2011 22:00:20

Message: 5 of 10

Hi,
>But if you're looking at the (ri)th element, say (row=3, column = 2),
> where exactly is the (ri+25-1)th element? What row and column would
> that be in?
the globalarry is a one row vector.

>And then do you just scan the grid as ri goes from 1 to
> numel(globalarry) and check the (ri+25-1) the element?
Yes.

>What happens
> when that element if past the end of the array, for example when
> ri>numel(globalarry)-24? In that case (ri+25-1) will be greater than
> the number of elements in globalarry.
You are right. I do have problem when the element out of the boundary.

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <90c2281a-6e99-4634-8f8e-715850447efc@c1g2000yqe.googlegroups.com>...
> On May 30, 3:41 pm, "furla furr" <furlaf...@yahoo.com> wrote:
> > Hope that I have give clearer explanation.
> --------------------------------------------------
> Nope, didn't do it for me. All I could figure out is that you're
> trying to do some kind of simulation with pedestrians walking on a
> grid, and that there are some conditions where certain elements will
> get set to 1.
>
> But if you're looking at the (ri)th element, say (row=3, column = 2),
> where exactly is the (ri+25-1)th element? What row and column would
> that be in? And then do you just scan the grid as ri goes from 1 to
> numel(globalarry) and check the (ri+25-1) the element? What happens
> when that element if past the end of the array, for example when
> ri>numel(globalarry)-24? In that case (ri+25-1) will be greater than
> the number of elements in globalarry.

Subject: cellarray

From: ImageAnalyst

Date: 31 May, 2011 00:44:25

Message: 6 of 10

If I enter your code into MATLAB, it gives globalarry as a 15 row by 5
column 2D array. Even if I use reshape to turn it into a row vector,
I don't know what you want to do.

Maybe it's this:
for ri = 1 : numel(globalarry)-24
    % Get the second index 24 elements away.
    ri2 = ri + 24; % Same as +25-1.
    % Get the values at those two locations.
    value1 = globalarry(ri);
    value2 = globalarry(ri2);
    % Then what?
end


 We'll be ready to help when you explain the complete situation
better. It's possible that conv() might help you - but I can't really
be sure since I don't understand what you're doing or wanting to do.

Subject: cellarray

From: furla furr

Date: 31 May, 2011 10:36:04

Message: 7 of 10

Hi,

Again, many thanks for your help.

I try another method. Now I changed the matrix to 3 matrices with (5x5).
I'm going to compare the position of ri in the first matrix with the position ri-1 in the second matrix. and continue to compare the position of ri in second matrix with the position of ri-1 in the third matrix.

If it is not fulfill the 'rule', I'm going to update my 'heatmap' matrix(5x5) which I initially setup to all zeros with one. In the 'heatmap', the updated position is the same position with ri in first matrix and continue to increase by one with the same ri position of second matrix.

The problem is; how do I compare the ri element from first matrix, with ri-1 element of the second matrix and so on...

Thanks,
Furla
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <dac6786f-55a8-412e-ab0f-6cfda68c59a7@l18g2000yql.googlegroups.com>...
> If I enter your code into MATLAB, it gives globalarry as a 15 row by 5
> column 2D array. Even if I use reshape to turn it into a row vector,
> I don't know what you want to do.
>
> Maybe it's this:
> for ri = 1 : numel(globalarry)-24
> % Get the second index 24 elements away.
> ri2 = ri + 24; % Same as +25-1.
> % Get the values at those two locations.
> value1 = globalarry(ri);
> value2 = globalarry(ri2);
> % Then what?
> end
>
>
> We'll be ready to help when you explain the complete situation
> better. It's possible that conv() might help you - but I can't really
> be sure since I don't understand what you're doing or wanting to do.

Subject: cellarray

From: ImageAnalyst

Date: 31 May, 2011 11:12:13

Message: 8 of 10

Please define "compare" do you mean equals or not equals, greater or
less than, what????

Why not just use for loops and do it the brute force way. At least
you'll understand what you did, and you don't need to worry about for
loops for microscopic arrays like this - they'll be so fast you won't
notice any speed difference.

Subject: cellarray

From: furla furr

Date: 1 Jun, 2011 06:01:07

Message: 9 of 10

Hi,

is to 'compare' whether position ri in the first matrix is equal to value '1'. if yes, it will also check whether the position of ri-1 in the second matrix is NOT equal to value '1'. Then, it will increase position ri of result matrix to one. the updated position of ri in result matrix must be the same with position ri of the first matrix.

I will try the for loops technique. But not so sure about the bruce force way as I don't have any idea about it.

Thanks again,

Furla
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <8db3f06a-6bef-4d0c-92e7-4f95857c50c5@w21g2000yqm.googlegroups.com>...
> Please define "compare" do you mean equals or not equals, greater or
> less than, what????
>
> Why not just use for loops and do it the brute force way. At least
> you'll understand what you did, and you don't need to worry about for
> loops for microscopic arrays like this - they'll be so fast you won't
> notice any speed difference.

Subject: cellarray

From: ImageAnalyst

Date: 1 Jun, 2011 11:17:32

Message: 10 of 10

"Brute force" just means the most obvious and intuitive way, though
not necessarily the most efficient way. It may not be the most clever
or compact way but it's easy to understand, easy to code up, and easy
to maintain. Using for loop(s) is such a brute force method.

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com