How to concatenate different rows

4 次查看(过去 30 天)
Della N
Della N 2020-4-2
评论: Rik 2020-4-4
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 个评论
Rik
Rik 2020-4-3
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?

请先登录,再进行评论。

回答(1 个)

Rik
Rik 2020-4-2
编辑:Rik 2020-4-3
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 个评论
Della N
Della N 2020-4-4
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 2020-4-4
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by