merge multiple 4-D double
2 次查看(过去 30 天)
显示 更早的评论
hello, i am using delft3d for my hydrodynamics simulations. Delft3D exports to .mat version 7 files.
so my quiestion is, how can i join this 4 variables into one for each filename?
Name Size Bytes Class Attributes
Zp1 2500x71x42x6 357840000 double
Zp2 2500x71x42x6 357840000 double
Zp3 2500x71x42x6 357840000 double
Zp4 1284x71x42x6 183786624 double
a4_salin_6c_p1 2500x71x42x6 357840000 double
a4_salin_6c_p2 2500x71x42x6 357840000 double
a4_salin_6c_p3 2500x71x42x6 357840000 double
a4_salin_6c_p4 1284x71x42x6 183786624 double
dt_p1 2500x1 40001 datetime
dt_p2 2500x1 40001 datetime
dt_p3 2500x1 40001 datetime
dt_p4 1284x1 20545 datetime
jd_p1 2500x1 20000 double
jd_p2 2500x1 20000 double
jd_p3 2500x1 20000 double
jd_p4 1284x1 10272 double
any ideas?
please help, since its very time consuming to manage multiple files for every single variable that i have to used.
3 个评论
采纳的回答
Guillaume
2017-11-28
Numbered variables are always a bad idea. Much better would be to just have one variable (a cell array in your case) containing all the arrays in these numbered variables. But perhaps you have no control over that from your export function.
So, first step would be to create that container:
numvars = 4; %adjust as required
varprefix = 'Zp'; %adjust as required
container = cell(1, numvars); %container for the variables
for varidx = 1:numvars
eval(sprintf('container{%2$d} = %1$s%2$d', varprefix, varidx))
end
Once that is done, it is trivial to vertically concatenate the matrices in the container into one matrix with cat or vertcat as per Rik's comment:
Zp = vertcat(container{:}); %That's all that is required
Note that we're using eval here to fix the mess that is the numbered variables. See matlab's documentation for why eval and numbered variables are bad.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!