merge multiple 4-D double

3 次查看(过去 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 个评论
roberto ivan perez luna
ok, i'll change the numers ;)
i need them to be like this:
8748x71x42x6 for "Zp" and a4_salin_6c
and for the dates in gregorian and julian, like this:
8784x1 for dt and jd
ok, so i look up for "cat" function, and thats it?
Rik
Rik 2017-11-28
That should be it.

请先登录,再进行评论。

采纳的回答

Guillaume
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 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by