Concatenating a large number or matrices

7 次查看(过去 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
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
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by