How to concatenate different rows

4 views (last 30 days)
Della N
Della N on 2 Apr 2020
Commented: Rik on 4 Apr 2020
Hello, i have some trouble doing my project. I have 2 different mat file (skak1.mat with 268x1000000 dimension and skak2.mat with 63x1000000 dimension) I want to concatenate 2 files above. Anyone can help me please?
  5 Comments
Rik
Rik on 3 Apr 2020
Just to have the situation clear:
You have two files 'E:\Matlab\skak1.mat' and 'E:\Matlab\skak2.mat'. The first contains a variable called skak1 (268x1000000) and the second contains a variable called skak2 (63x1000000). Your goal is to have a mat file 'E:\Matlab\new skak.mat' that contains a variable skak_new (331x1000000).
Is that all correct?

Sign in to comment.

Answers (1)

Rik
Rik on 2 Apr 2020
Edited: Rik on 3 Apr 2020
You can't concatenate files. (Technically you can, but showing how you could do it will not be helpful for you)
What you need to do is load the two matrices with the load function, after which you can concatenate them as any other variable.
pathname = 'E:\Matlab'
S=load(fullfile(pathname,'skak1.mat'));
skak1=S.skak1;
S=load(fullfile(pathname,'skak2.mat'));
skak2=S.skak2;
skak_new=[skak1;skak2];
save(fullfile(pathname,'new skak.mat'),'skak_new');
As long as everything fits in memory the above code should do what you need. That might be your main issue, since the result will require about 2.5 GB of contiguous memory (so 5 GB in total). If this is a problem for you, please comment below and I will try to help you with a way to write to mat files without loading everything in memory. For that it is important to know which release of Matlab you are using.
  8 Comments
Della N
Della N on 4 Apr 2020
I hv tried the new code but my pc are getting slower and cant do anything, but still running the code. What should i do? Waiting till end or i can try another choice? Thankyou.
Rik
Rik on 4 Apr 2020
You are probably near the maximum variable size your computer can handle. You can check in your task manager whether the RAM is almost full and whether the disk is active because of page swapping. If it takes more than about 15 minutes I would expect something to be wrong.
I think another conclusion is that your computer is not suitable for working with this data size.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!