How to concatenate two or more MATLAB files in a single file?

1 view (last 30 days)
Suppose file A(1 * 36), B(1 * 30), C(1* 25), D(1* 40), E(1* 45) and now i want to merge all these values in one file, to make a single file e.g, X(5 * 45)

Answers (1)

dpb
dpb on 10 Mar 2014
Can't directly because Matlab arrays can't be jagged but rectangular.
You can either augment the shorter to the longest by padding w/ zero or an indicator value (NaN often used for this purpose) or use a cell array if that's not palatable.
Either way you'll have to read the files into memory first--assuming you've don so then
L=45; % I just looked; you'll want to code max(length(A), ...) to automate
X=[A nan(1,L-length(A)); ...
B nan(1,L-length(B)); ...
...
E];
or, the cell array approach
X={A;B;C;D;E};
Only your subsequent usage can determine which is the better approach.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!