Code covered by the BSD License  

Highlights from
DEALCELL

5.0

5.0 | 1 rating Rate this file 5 Downloads (last 30 days) File Size: 2.06 KB File ID: #10162

DEALCELL

by Jiro Doke

 

26 Feb 2006 (Updated 02 Nov 2010)

Deals cell elements to variables (similar to DEAL)

| Watch this File

File Information
Description

DEALCELL Deals cell elements to variables

[A1,A2,A3,...] = DEALCELL(X) assigns elements of cell array X to output lists. It is the same as A1=X{1}, A2=X{2}, A3=X{3}, ..., AN=X{N}. There can be any number of variables (up to the total number of elements in X) on the left hand side. If there are fewer LHS variables than the total number of elements in X, then only the first N elements of X are assigned.

DEALCELL works similarly to DEAL, except that it is specialized for cell array inputs and that the cell array does not have to be passed in as comma-separated lists.

This is a very short code (0 lines), and for cell array dealing, it is faster than DEAL.

The code:
 function varargout = dealcell(varargout)

Helpful error messages are sacrificed for efficiency. To enable better error-checking, uncomment the Error Checking section below.

Example: (speed comparison with DEAL)
 sys={'hello'; 'yes'; 'no'; 'goodbye'};
 tic; % DEALCELL
 for id = 1:100000
  [a1,b1,c1,d1] = dealcell(sys);
 end
 fprintf('\nDEALCELL: %1.3f sec (%d iterations)\n', toc, id);

 tic; % DEAL
 for id = 1:100000
  [a2,b2,c2,d2] = deal(sys{:});
 end
 fprintf('DEAL : %1.3f sec (%d iterations)\n\n', toc, id);
 isequal({a1,b1,c1,d1},{a2,b2,c2,d2})

See also DEAL, LISTS, PAREN.

***
This is a simplification to DEAL, to be used with cell arrays specifically. Comments on its usefulness are welcome. Thanks.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
27 Feb 2006 Jiro Doke

An even (very) simpler version is on the way. The newest version can also be downloaded here:

http://www-personal.umich.edu/~jdokeh/mfiles/dealcell.m

27 Feb 2006 Jos van der Geest

I have some doubts about its usefullness and much prefer using the intermediate variable + deal solution. Help and programming is good, except for:
>> sys = ['hello '; 'yes '; 'no '; 'goodbye'];
??? Error using ==> vertcat
All rows in the bracketed expression must have the same number of columns.

27 Feb 2006 Jiro Doke

Thanks Jos for your input. As for the example, I think the spaces got messed up when I copy/pasted to the FEX site. If you use the actual help text, it should work.

Yes, I guess there is little benefit to the small simplification here. What do you think about the new version I posted on my website (see link in my previous comment)? I was quite amused when I created this 0-line code. :)

18 Mar 2009 MATLABician

A 0-line function deserving a 5 star rating. Intelligent use of varargout with COW strategy in mind.

Please login to add a comment or rating.
Updates
28 Feb 2006

Simplify engine. Strip down code to 0 lines.

03 Mar 2006

Modify help text

02 Nov 2010

License update

Tag Activity for this File
Tag Applied By Date/Time
matrices Jiro Doke 22 Oct 2008 08:16:57
deal Jiro Doke 22 Oct 2008 08:16:57
assign Jiro Doke 22 Oct 2008 08:16:57
distribute Jiro Doke 22 Oct 2008 08:16:57
cell array Jiro Doke 22 Oct 2008 08:16:57

Contact us at files@mathworks.com