1.0

1.0 | 1 rating Rate this file 9 downloads (last 30 days) File Size: 1.26 KB File ID: #18507

interweave

by John T. McCarthy

 

29 Jan 2008 (Updated 24 Jan 2009)

Code covered by the BSD License  

This function interweaves (alternates/overlaps) the columns of equal-sized matrices A,B,C...

Download Now | Watch this File

File Information
Description

The first column of the output is the first column of A.
The second column of the output is the first column of B, followed by C etc.
Then the second columns of A,B,C...
The final column of the output is the final column of the last input matrix.

Example: A = ones(3); B = ones(3)*2;
C = ones(3)*3; D = interweave(A,B,C)

MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
29 Jan 2008 Yi Cao

The code has a bug. If the number of rows is larger than the total number of columns of all inputs, then line 24, which uses length(input) will generate an error.

I also believe that such a task can be done in a much simpler way without the need of a loop.

29 Jan 2008 Jos x@y.z

The fact that this function has a help section is good. However, as it is now, it errors on some input, and the same task can be accomplished by the following one-liner:

function X = fun(varargin)
X = reshape(cat(1,varargin{:})],size(varargin{1},1),[]) ;

to which you can add error checks

30 Jan 2008 Duane Hanselman

For an alternative try the other "interlace" function on the File Exchange: File Id 10060

Please login to add a comment or rating.
Updates
29 Jan 2008

Removed bug

30 Jan 2008

Removed typo in description.

30 Jan 2008

Changed filename from interlace to interweave, to avoid name duplication.

04 Feb 2008

Simplified the code.

29 Aug 2008

Change category to 'Matrix Manipulation'

24 Jan 2009

Added the tag 'overlap'

Tag Activity for this File
Tag Applied By Date/Time
matrices John T. McCarthy 22 Oct 2008 09:45:19
interweave John T. McCarthy 22 Oct 2008 09:45:19
interlace John T. McCarthy 22 Oct 2008 09:45:19
columns John T. McCarthy 22 Oct 2008 09:45:19
alternate John T. McCarthy 22 Oct 2008 09:45:19
overlap John T. McCarthy 26 Jan 2009 15:26:07
matrix manipulation John T. McCarthy 09 Feb 2009 19:31:41
 

MATLAB Central Terms of Use

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 Terms prior to use.

Contact us at files@mathworks.com