How to join matrices of different lengths into one mother matrix
Show older comments
Dear Matlab,
I have an EEG signal dataset with 14 files.
GOAL: to join all files together into one mother uber matrix, i.e. similar to 'concatenate', so I can run stats.
The problem is (I think) that the files have different lengths. Some files are 5 minutes long, others are 10 minutes, etc. They have the same number of channels (i.e. 'rows'), but the datapoints, or 'columns' are different. How can I join them together? Please help. Thank you very much in advance. (Also I don't want to truncate to the shortest length, because I lose data).
- Below is the code I have. (tried attahcing sample datafiles but too large)
************************************
close all; clear; clc;
% Get a list of data files ready to be analyzed
sublist = dir('*.mat');
sublist = {sublist.name};
% load in level-1 data
for subno=1:length(sublist)
load(sublist{subno})
% initialize matrices on 1st subject
if subno==1
GROUPsig = zeros([ length(sublist) size(dataFCP_pow2) ]);
end % end initialization loop
GROUPsig(subno,:,:) = dataFCP_pow2;
end % end loop around subjects
4 Comments
Image Analyst
on 5 Feb 2023
Edited: Image Analyst
on 5 Feb 2023
Your input data are 2-D matrices, right? What do you want as the output array? A single 1-D vector with all the data stitched together, or a 2-D array with each file in one row, or a cell array?
Have you tried scanning the 14 files first and then making a 2-D array with as many columns as the longest of them, then make another pass putting the data into the matrix? You'd have to keep track of the next column to write into after each file is put into the array.
Joanne Hall
on 5 Feb 2023
Image Analyst
on 5 Feb 2023
Can you crop down 2 or 3 files and attach them? But I agree with Paul below. It sounds like what you are suggesting would just complicate things for no reason. What do you plan on doing with this 3-D matrix once you've created it?
Joanne Hall
on 5 Feb 2023
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification 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!