How to concatenate different rows
조회 수: 3 (최근 30일)
이전 댓글 표시
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
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
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
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
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 Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!