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:
Reshape function

Subject: Reshape function

From: Muhammad Imran

Date: 16 Jul, 2012 05:03:22

Message: 1 of 5

I am using reshape function like below
pixel_labels = reshape(data_idxs,6,6144);

here data_idxs is a 6144X1 vector return by the kmenas
6 are the rows of my original vector that i input to the kmeans and 6144 are the columns of the origional vector.

when i run this code it give me the fallowing error
??? Error using ==> reshape
To RESHAPE the number of elements must not change.

please help me. actually i want to print the segmented image.

Subject: Reshape function

From: TideMan

Date: 16 Jul, 2012 05:59:37

Message: 2 of 5

On Monday, July 16, 2012 5:03:22 PM UTC+12, Muhammad Imran wrote:
> I am using reshape function like below
> pixel_labels = reshape(data_idxs,6,6144);
>
> here data_idxs is a 6144X1 vector return by the kmenas
> 6 are the rows of my original vector that i input to the kmeans and 6144 are the columns of the origional vector.
>
> when i run this code it give me the fallowing error
> ??? Error using ==> reshape
> To RESHAPE the number of elements must not change.
>
> please help me. actually i want to print the segmented image.

Try:
pixel_labels = reshape(data_idxs,6,[]);

Subject: Reshape function

From: Nasser M. Abbasi

Date: 16 Jul, 2012 06:00:24

Message: 3 of 5

On 7/16/2012 12:03 AM, Muhammad Imran wrote:
> I am using reshape function like below
> pixel_labels = reshape(data_idxs,6,6144);
>
> here data_idxs is a 6144X1 vector return by the kmenas


You can't do that.

If matrix is say 5 rows by 1 columns, you can't change its
shape to 6 rows by 5 columns. The new size will be larger.

reshape can't generate data on its own to make up for the missing size.

This like the law of conservation of energy in physics, which
says that total energy in an enclosed space can't change over
time. It can change form, but not in quantity.

--Nasser

Subject: Reshape function

From: Muhammad Imran

Date: 16 Jul, 2012 06:40:13

Message: 4 of 5

"Nasser M. Abbasi" <nma@12000.org> wrote in message <ju0alo$hkq$1@speranza.aioe.org>...
> On 7/16/2012 12:03 AM, Muhammad Imran wrote:
> > I am using reshape function like below
> > pixel_labels = reshape(data_idxs,6,6144);
> >
> > here data_idxs is a 6144X1 vector return by the kmenas
>
>
> You can't do that.
>
> If matrix is say 5 rows by 1 columns, you can't change its
> shape to 6 rows by 5 columns. The new size will be larger.
>
> reshape can't generate data on its own to make up for the missing size.
>
> This like the law of conservation of energy in physics, which
> says that total energy in an enclosed space can't change over
> time. It can change form, but not in quantity.
>
> --Nasser
>
Then how can i reprint the segmented image.

Subject: Reshape function

From: Muhammad Imran

Date: 16 Jul, 2012 06:47:07

Message: 5 of 5

TideMan <mulgor@gmail.com> wrote in message <67077df8-b25e-48b8-9674-b4e1579b30e8@googlegroups.com>...
> On Monday, July 16, 2012 5:03:22 PM UTC+12, Muhammad Imran wrote:
> > I am using reshape function like below
> > pixel_labels = reshape(data_idxs,6,6144);
> >
> > here data_idxs is a 6144X1 vector return by the kmenas
> > 6 are the rows of my original vector that i input to the kmeans and 6144 are the columns of the origional vector.
> >
> > when i run this code it give me the fallowing error
> > ??? Error using ==> reshape
> > To RESHAPE the number of elements must not change.
> >
> > please help me. actually i want to print the segmented image.
>
> Try:
> pixel_labels = reshape(data_idxs,6,[]);

Thanks i used it but now in printed image i cannot see the image itself the only lines i can see.

i don't know how to attach that image with this post..

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