Concatenating a large number or matrices
조회 수: 8 (최근 30일)
이전 댓글 표시
So I have a number of matrices, most of which have a common naming convention (temp_Xkm). Each was originally a file that was loaded in (of the format: temp_Xkm.dat). There is one file name t1.dat.
I would like to easily concatenate them (assuming that a loop is easier). Below is what I have for the long way, handjamming it in, and the short way, trying to loop it.
My loop attempt has been unsuccessful and I'm lost on where to go from here.
Thanks for any help!
%the long way
T3D = cat(11, t1, temp_1km, temp_2km, temp_3km, temp_4km, temp_8km...
, temp_11km, temp_14km, temp_15km, temp_16km, temp_17km);
%the short way?
for Tii = [1,2,3,4,8,11,14,15,16,17];
TC = cat(11, t1, ['temp_' num2str(Tii) 'km'])
Alltemps_vec(Tii)= TC;
end
댓글 수: 3
KSSV
2019년 2월 19일
YOu hav to read the .dat files ina loop and join them.......the way you are following is not correct...
Stephen23
2019년 2월 19일
"My loop attempt has been unsuccessful and I'm lost on where to go from here."
Change how you import that data. Instead of dynamically creating lots of variable names simply import the data into one array using indexing, exactly as the MATLAB documentation shows:
Simple indexing is neat, trivially easy to use, and very efficient, unlike what you are trying to do.
Dynamically accessing variable names is one way that beginners force themselves into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know some of the reasons why:
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!