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:
manipulation

Subject: manipulation

From: ravi

Date: 3 Jun, 2010 17:59:07

Message: 1 of 10

Hi guys,

I have a matrix X
X =

         658 1072
          96 103
         760 1089
         292 298
   

I wish INSTEAD to output like this:

X = 658 1072 96 103
      760 1089 292 298
   

Can anyone suggest something


ravi

Subject: manipulation

From: Jan Simon

Date: 3 Jun, 2010 19:03:04

Message: 2 of 10

Dear Ravi!

> I have a matrix X
> X =
> 658 1072
> 96 103
> 760 1089
> 292 298
>
> I wish INSTEAD to output like this:
> X = 658 1072 96 103
> 760 1089 292 298

Do you mean something like this:
  fprintf('%s = %g %g %g %g\n', 'X', transpose(X(1, :));
  fprintf(' %g %g %g %g\n', transpose(X(2:end, :));

Jan

Subject: manipulation

From: ravi

Date: 3 Jun, 2010 19:04:21

Message: 3 of 10

i would like to do this in some kind off loop assuming X would get larger by 2 rows incrementally


Ravi




"ravi " <ravi_071@hotmail.com> wrote in message <hu8qhb$pq1$1@fred.mathworks.com>...
> Hi guys,
>
> I have a matrix X
> X =
>
> 658 1072
> 96 103
> 760 1089
> 292 298
>
>
> I wish INSTEAD to output like this:
>
> X = 658 1072 96 103
> 760 1089 292 298
>
>
> Can anyone suggest something
>
>
> ravi

Subject: manipulation

From: ravi

Date: 3 Jun, 2010 19:15:37

Message: 4 of 10

Thanks Jan,but When I use your solution it has some parentheses error

Ravi










"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hu8u98$bst$1@fred.mathworks.com>...
> Dear Ravi!
>
> > I have a matrix X
> > X =
> > 658 1072
> > 96 103
> > 760 1089
> > 292 298
> >
> > I wish INSTEAD to output like this:
> > X = 658 1072 96 103
> > 760 1089 292 298
>
> Do you mean something like this:
> fprintf('%s = %g %g %g %g\n', 'X', transpose(X(1, :));
> fprintf(' %g %g %g %g\n', transpose(X(2:end, :));
>
> Jan

Subject: manipulation

From: Jan Simon

Date: 3 Jun, 2010 20:00:26

Message: 5 of 10

Dear Ravi!

> > fprintf('%s = %g %g %g %g\n', 'X', transpose(X(1, :));
> > fprintf(' %g %g %g %g\n', transpose(X(2:end, :));
> > Jan

> Thanks Jan,but When I use your solution it has some parentheses error
> Ravi

Yes, I obviously forgot the closing parentheses. I think you can fix this.

Jan

Subject: manipulation

From: ravi

Date: 3 Jun, 2010 20:16:07

Message: 6 of 10

Hi Jan,

I want it something like this in matlab:


X =[ 658 1072 96 103 ;760 1089 292 298]
>> X =
               658 1072 96 103
               760 1089 292 298

thanks ravi

Subject: manipulation

From: Jan Simon

Date: 3 Jun, 2010 21:06:19

Message: 7 of 10

Dear Ravi!


> I want it something like this in matlab:
> X = [658 1072 96 103 ;760 1089 292 298]
> >> X =
> 658 1072 96 103
> 760 1089 292 298

I'm getting more confused.
If I define this in Matlab:
  X = [658 1072 96 103 ;760 1089 292 298]
I get immediately:
   X =
                658 1072 96 103
                760 1089 292 298
Do you want something else?

In the first post you asked for this:
> I have a matrix X
> X =
> 658 1072
> 96 103
> 760 1089
> 292 298
> I wish INSTEAD to output like this:
> X = 658 1072 96 103
> 760 1089 292 298

Do you want to reorder the elements?
Perhaps:
  reshape(permute(x', 2, 2, 2), [3, 1, 2]), 2, 4)

Jan

Subject: manipulation

From: ravi

Date: 3 Jun, 2010 21:23:05

Message: 8 of 10

Ok Jan,

I'll try to rephrase exactly what I am trying to do.

I have a matrix:
X = [658 1072 ;96 103 ;760 1089;292 298]

Now, Matlab outputs it like the following:

X =

         658 1072
          96 103
         760 1089
         292 298

However, my aim is to get X to be reshaped somehow like the following:

>> X =
               658 1072 96 103
               760 1089 292 298

If I can get a solution to solve this problem for an X matrix of any size this would be great.Hope this helps you out and thanks again for the help .

ravi

Subject: manipulation

From: us

Date: 3 Jun, 2010 21:24:06

Message: 9 of 10

"ravi " <ravi_071@hotmail.com> wrote in message <hu8qhb$pq1$1@fred.mathworks.com>...
> Hi guys,
>
> I have a matrix X
> X =
>
> 658 1072
> 96 103
> 760 1089
> 292 298
>
>
> I wish INSTEAD to output like this:
>
> X = 658 1072 96 103
> 760 1089 292 298
>
>
> Can anyone suggest something
>
>
> ravi

this does the col-row RESHAPEing

http://www.mathworks.com/matlabcentral/fileexchange/20255

us

Subject: manipulation

From: Roger Stafford

Date: 3 Jun, 2010 22:04:37

Message: 10 of 10

"ravi " <ravi_071@hotmail.com> wrote in message <hu8ubl$gt7$1@fred.mathworks.com>...
> i would like to do this in some kind off loop assuming X would get larger by 2 rows incrementally
> Ravi
>
> "ravi " <ravi_071@hotmail.com> wrote in message <hu8qhb$pq1$1@fred.mathworks.com>...
> > Hi guys,
> >
> > I have a matrix X
> > X =
> >
> > 658 1072
> > 96 103
> > 760 1089
> > 292 298
> >
> > I wish INSTEAD to output like this:
> >
> > X = 658 1072 96 103
> > 760 1089 292 298
> >
> > Can anyone suggest something
> > ravi
- - - - - - - - -
  I gather you want to always end up with four columns and each row is made up of the elements from two successive rows of the original X. How about this:

 X = reshape(X.',4,[]).';

Roger Stafford

Tags for 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