Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: reshape problem

Subject: reshape problem

From: Marcel

Date: 02 Feb, 2008 21:27:02

Message: 1 of 3

Hi i have this script
I want to reshape matrix A to matrix C with different number
 of collums and rows

 A=[1 1 1 1 1;2 2 2 2 2;3 3 3 3 3 ;4 4 4 4 4 ;5 5 5 5 5];
 C=[];
 [m,n]=size(A);
 p=m*n;
 if p/8==0
     d=p/8;
     C=reshape(A,8,d)
 else
     for i=1:7
        while p/8==0
            
            p=m*(n+i);
            d=p/8;
           C=reshape(A,d,8)
         end
         
         end
          
     end
    
 end

but there is an error..

??? Undefined function or variable 'C'.

Error in ==> C:\MATLAB6p5\work\TEST.m

where is the problem?
please let me know.
Thanks



Subject: Re: reshape problem

From: Nasser Abbasi

Date: 02 Feb, 2008 21:50:07

Message: 2 of 3


"Marcel " <JMarcel2@gmail.com> wrote in message
news:fo2n76$rk$1@fred.mathworks.com...
> Hi i have this script
> I want to reshape matrix A to matrix C with different number
> of collums and rows
>
> A=[1 1 1 1 1;2 2 2 2 2;3 3 3 3 3 ;4 4 4 4 4 ;5 5 5 5 5];
> C=[];
> [m,n]=size(A);
> p=m*n;
> if p/8==0
> d=p/8;
> C=reshape(A,8,d)
> else
> for i=1:7
> while p/8==0
>
> p=m*(n+i);
> d=p/8;
> C=reshape(A,d,8)
> end
>
> end
>
> end
>
> end
>
> but there is an error..
>
> ??? Undefined function or variable 'C'.
>
> Error in ==> C:\MATLAB6p5\work\TEST.m
>
> where is the problem?
> please let me know.
> Thanks
>
>

hello;

That is a little strange code you have there. I am not sure I understand it.

You say that if p/8 is zero then do something else you enter into some loop
which runs while p/8 is zero?? How are you going to have that while be true
if you are there because it is not true in the first place? there is nothing
there which would change that test.

(ps. you also seem to have an extra end hanging at the end)
(pps. it is not a good idea to check for equality between floating points
numbers using ==, help eps)

Nasser


Subject: reshape problem

From: Roger Stafford

Date: 02 Feb, 2008 22:02:01

Message: 3 of 3

"Marcel " <JMarcel2@gmail.com> wrote in message <fo2n76$rk
$1@fred.mathworks.com>...
> Hi i have this script
> I want to reshape matrix A to matrix C with different number
> of collums and rows
>
> A=[1 1 1 1 1;2 2 2 2 2;3 3 3 3 3 ;4 4 4 4 4 ;5 5 5 5 5];
> C=[];
> [m,n]=size(A);
> p=m*n;
> if p/8==0
> d=p/8;
> C=reshape(A,8,d)
> else
> for i=1:7
> while p/8==0
>
> p=m*(n+i);
> d=p/8;
> C=reshape(A,d,8)
> end
>
> end
>
> end
>
> end
>
> but there is an error..
>
> ??? Undefined function or variable 'C'.
>
> Error in ==> C:\MATLAB6p5\work\TEST.m
>
> where is the problem?
> please let me know.
> Thanks
--------
  The quantity p/8 (= 25/8) is not zero, so in the 'else' part the 'while' loop
never gets started in any of the seven trips through the 'for' loop.

Roger Stafford


Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
reshape Marcel 02 Feb, 2008 16:30:07
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics