merge multiple 4-D double

3 visualizaciones (últimos 30 días)
roberto ivan perez luna
roberto ivan perez luna el 28 de Nov. de 2017
Respondida: Guillaume el 28 de Nov. de 2017
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 comentarios
roberto ivan perez luna
roberto ivan perez luna el 28 de Nov. de 2017
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 el 28 de Nov. de 2017
That should be it.

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 28 de Nov. de 2017
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.

Más respuestas (0)

Categorías

Más información sobre Variables en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by