From: Anthony Hopf on
I know there are functions like rot90 to rotate a matrix about a point, but you need the the matrix. I only have the linear index values of the matrix. I can easily shift the indexes by adding or subtracting either row or column values... but what if I wanted to rotate by 90 or 180 degrees... is this possible with just the index values?

-one idea I had was to progressively subtract (or add depending on which way I want to shift) more from each row index, but I don't have them in a specific order to implement this progressive shift.

here is a small example:

A = [ 11 22 33 44 55; 66 77 88 99 1010]

idx(1,1) = [1 6 ]
idx(1,2) = [2 7 ]
idx(1,3) = [3 8]
idx(1,4) = [4 9]
idx(1,5) = [5 10]

and get

A_shift = [55 44 33 22 11; 1010 99 88 77 66] without ever seeing A... but knowing its size and dimensions.

confusing? thank you for the help... I know I've been asking quite a few questions lately but I am learning a lot!!
From: TideMan on
On May 25, 1:54 pm, "Anthony Hopf" <anthony.h...(a)gmail.com> wrote:
> I know there are functions like rot90 to rotate a matrix about a point, but you need the the matrix.  I only have the linear index values of the matrix.  I can easily shift the indexes by adding or subtracting either row or column values... but what if I wanted to rotate by 90 or 180 degrees.... is this possible with just the index values?
>
> -one idea I had was to progressively subtract (or add depending on which way I want to shift) more from each row index, but I don't have them in a specific order to implement this progressive shift.
>
> here is a small example:
>
> A = [ 11 22 33 44 55; 66 77 88 99 1010]
>
> idx(1,1) = [1 6 ]
> idx(1,2) = [2 7 ]
> idx(1,3) = [3 8]
> idx(1,4) = [4 9]
> idx(1,5) = [5 10]
>
> and get
>
> A_shift = [55 44 33 22 11; 1010 99 88 77 66] without ever seeing A... but knowing its size and dimensions.
>
> confusing?  thank you for the help... I know I've been asking quite a few questions lately but I am learning a lot!!

I'm afraid your example makes no sense to me at all.
For example, what does:
idx(1,1)=[1 6]
mean?
There is one slot on the LHS, but 2 slots on the RHS, so that can't
work.

But to get A_shift from A, you don't need to screw around like that,
just do:
A_shift=fliplr(A);
From: Walter Roberson on
Anthony Hopf wrote:
> I know there are functions like rot90 to rotate a matrix about a point,
> but you need the the matrix. I only have the linear index values of the
> matrix. I can easily shift the indexes by adding or subtracting either
> row or column values... but what if I wanted to rotate by 90 or 180
> degrees... is this possible with just the index values?

> and get
>
> A_shift = [55 44 33 22 11; 1010 99 88 77 66] without ever seeing A...
> but knowing its size and dimensions.

Yes, if you know the dimensions then you can calculate it.

[orig_row, orig_col] = ind2sub([A_rows, A_cols], A);
new_row_r90 = A_cols + 1 - orig_col;
new_col_r90 = orig_row;
A_shift = sub2ind([A_cols, A_row], new_row_r90, new_col_r90);

If you really wanted to, you could combine this all into a single formula.
From: Anthony Hopf on
TideMan <mulgor(a)gmail.com> wrote in message <6fc95e16-178c-4bc0-b4f4-ee7e5fe58d93(a)x27g2000prf.googlegroups.com>...
> On May 25, 1:54 pm, "Anthony Hopf" <anthony.h...(a)gmail.com> wrote:
> > I know there are functions like rot90 to rotate a matrix about a point, but you need the the matrix.  I only have the linear index values of the matrix.  I can easily shift the indexes by adding or subtracting either row or column values... but what if I wanted to rotate by 90 or 180 degrees... is this possible with just the index values?
> >
> > -one idea I had was to progressively subtract (or add depending on which way I want to shift) more from each row index, but I don't have them in a specific order to implement this progressive shift.
> >
> > here is a small example:
> >
> > A = [ 11 22 33 44 55; 66 77 88 99 1010]
> >
> > idx(1,1) = [1 6 ]
> > idx(1,2) = [2 7 ]
> > idx(1,3) = [3 8]
> > idx(1,4) = [4 9]
> > idx(1,5) = [5 10]
> >
> > and get
> >
> > A_shift = [55 44 33 22 11; 1010 99 88 77 66] without ever seeing A... but knowing its size and dimensions.
> >
> > confusing?  thank you for the help... I know I've been asking quite a few questions lately but I am learning a lot!!
>
> I'm afraid your example makes no sense to me at all.
> For example, what does:
> idx(1,1)=[1 6]
> mean?
> There is one slot on the LHS, but 2 slots on the RHS, so that can't
> work.
>
> But to get A_shift from A, you don't need to screw around like that,
> just do:
> A_shift=fliplr(A);

Sorry for the confusion. The example of matrix idx should be (1,:)...(5,:) where each idx row is a vector of index values from A. I'm pretty sure Walter has given the solution...

Thank you

Anthony
From: Anthony Hopf on
Walter Roberson <roberson(a)hushmail.com> wrote in message <nvGKn.18764$Gx2.3351(a)newsfe20.iad>...
> Anthony Hopf wrote:
>
> > and get
> >
> > A_shift = [55 44 33 22 11; 1010 99 88 77 66] without ever seeing A...
> > but knowing its size and dimensions.
>
> Yes, if you know the dimensions then you can calculate it.
>
> [orig_row, orig_col] = ind2sub([A_rows, A_cols], A);
> new_row_r90 = A_cols + 1 - orig_col;
> new_col_r90 = orig_row;
> A_shift = sub2ind([A_cols, A_row], new_row_r90, new_col_r90);
>
> If you really wanted to, you could combine this all into a single formula.

Walter,

Thank you, I'll play with this sample code... this is pretty tricky and a nice use of ind2sub and back that I would never have guessed, obviously. It looks like doing the other 90 deg rotation should be very easy too by subtracting from the "new_col_r90" matrix.

Thanks again!!

Anthony