Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Matrix to array
I have a cell array of 192 X 64.Now I need to convert
each of the individual cells back into matrix(cell2mat), then
populate a row of a new matrix with the contents of the cell.

Basically I have B = 192 * 64 cell.
each is of the form B(1,1)=2x2 double.
converting to matrix, B = cell2mat(B(1,1))
Now I need to put this into New(1,1:4)=[B(1,1) B(1,2) B(2,1) B(2,2)].


The question I have is whether this can be done in a easier way since
it is'nt always 192*64, I have to go through every single cell, and
it is'nt always 2x2.

Report this thread to moderator Post Follow-up to this message
Old Post
annie
04-28-05 09:06 AM


Re: Matrix to array
annie wrote:
>
>
> I have a cell array of 192 X 64.Now I need to convert
> each of the individual cells back into matrix(cell2mat), then
> populate a row of a new matrix with the contents of the cell.
>
> Basically I have B = 192 * 64 cell.
> each is of the form B(1,1)=2x2 double.
> converting to matrix, B = cell2mat(B(1,1))
> Now I need to put this into New(1,1:4)=[B(1,1) B(1,2) B(2,1)
> B(2,2)].
>
>
> The question I have is whether this can be done in a easier way
> since
> it is'nt always 192*64, I have to go through every single cell, and
>
> it is'nt always 2x2.
Help please!

Report this thread to moderator Post Follow-up to this message
Old Post
annie
04-28-05 09:06 AM


Re: Matrix to array
annie wrote:
>
>
> annie wrote: 
> and 
> Help please!

Reshape & Transpose (or .') are your friends ...

% create example data:
for i=1:10,
B{i} = repmat(i,2,2) ;
end
% NB All elements of B have equal elements
NewB = reshape(cell2mat(B),numel(B{1}),[]) .' ;

hth
Jos

-- no X-es in my email

Report this thread to moderator Post Follow-up to this message
Old Post
Jos
04-28-05 09:06 AM


Re: Matrix to array
annie wrote:
>
>
> annie wrote: 
> and 
> Help please!

There surely must be a more elegant and efficient way to do it, but
here's a start:

%%%%%%%%%%%%
newB = reshape(B', 1, []);

for i = 1:length(newB)
New(i, :) = reshape(newB{i}', 1, []);
end
%%%%%%%%%%%%

This is if you want to go across the rows first and down the columns
of B. If you want to go down the columns first, then

newB = {B{:}};

Hope this works.

jiro

Report this thread to moderator Post Follow-up to this message
Old Post
Jiro Doke
04-28-05 09:06 AM


Re: Matrix to array
Jiro Doke wrote:
>
>
> annie wrote: 
then 
cell. 
B(2,1) 
> way 
> cell, 
>
> There surely must be a more elegant and efficient way to do it, but
> here's a start:
>
> %%%%%%%%%%%%
> newB = reshape(B', 1, []);
>
> for i = 1:length(newB)
> New(i, :) = reshape(newB{i}', 1, []);
> end
> %%%%%%%%%%%%
>
> This is if you want to go across the rows first and down the
> columns
> of B. If you want to go down the columns first, then
>
> newB = {B{:}};
>
> Hope this works.
>
> jiro

Jos,
Very clever. Let me add another thing to your code. If I understand
the OP, she wants to display rows first:

newB = reshape(B', 1, []);
New =  reshape(cell2mat(newB')',numel(B{1}),[])
';

Report this thread to moderator Post Follow-up to this message
Old Post
Jiro Doke
04-28-05 09:06 AM


Re: Matrix to array
Jiro Doke wrote:
>
>
> Jiro Doke wrote: 
matrix(cell2mat),
> then 
> cell. 
> B(2,1) 
> easier 
single 
> but 
>
> Jos,
> Very clever. Let me add another thing to your code. If I
> understand
> the OP, she wants to display rows first:
>
> newB = reshape(B', 1, []);
> New =  reshape(cell2mat(newB')',numel(B{1}),[])
';

Jiro,Jos:

Thank you! You saved me a lot of time and more importantly I learnt
something.

Report this thread to moderator Post Follow-up to this message
Old Post
annie
04-28-05 02:00 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Matlab archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:27 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.