merge multiple 4-D double
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
roberto ivan perez luna
am 28 Nov. 2017
Beantwortet: Guillaume
am 28 Nov. 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 Kommentare
Akzeptierte Antwort
Guillaume
am 28 Nov. 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.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Variables finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!