MATLAB Answers

How to concatenate different rows

조회 수: 3(최근 30일)
Della N
Della N 2 Apr 2020
댓글: Rik 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

표시 이전 댓글 수: 2
Della N
Della N 3 Apr 2020
and last code i hv tried is here, but in the last code i haven't tried because my pc suddenly always turn off when i tried.
a1=load('skak1.mat');
f1=fieldnames(a1);
a2=load('skak2.mat');
f2=fieldnames(a2);
v=[a1.(f1{1});a2.(f2{1})];
save('new skak.mat','v');
Rik
Rik 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?
Della N
Della N 3 Apr 2020
yes alright sir.

로그인 to comment.

답변(1개)

Rik
Rik 2 Apr 2020
편집: Rik 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

표시 이전 댓글 수: 5
Rik
Rik 3 Apr 2020
Yes, that is the code you should use.
Della N
Della N 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 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.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

태그


Translated by