combine a number of files together? cat,vertcat and horzcat do not work...
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Michael
el 24 de Jul. de 2014
Comentada: Geoff Hayes
el 25 de Jul. de 2014
Hey all!
I have 254 files named blah_blah_001 until blah_blah_254. Each file has 723 x 3127 dimension and I want to combine all to create a 723 x 3127 x 254 matrix. I have tried loops but I am not sure how to write so that each file number is with 3 digits. Here is my attempt:
all = NaN(723,3127,254);
% attempt to put all arcs together..
for i=1:254;
for arc = 001:254;
all(:,:,i) = [TJJ_arc_(arc)]
end;
end;
After this I wish to calculate a nanmean to get 723 x 254...
Can someone help me?
2 comentarios
Respuesta aceptada
Geoff Hayes
el 24 de Jul. de 2014
Editada: Geoff Hayes
el 24 de Jul. de 2014
allData = NaN(723,3127,254);
for k=1:254
% create the file name
filename = sprintf('TJJ_arc_%03d.mat',k);
% load the data
data = load(filename);
% save the data
allData(:,:,k) = data;
end
NOTE that all is a built-in MATLAB function so your code should avoid using this as a variable name.
NOTE also how I replaced your iterator i with k. i and j are used in MATLAB as the representation of the imaginary number, so it is good practice to avoid using them in for loops.
Try the above and see what happens!
4 comentarios
Geoff Hayes
el 25 de Jul. de 2014
Cool. You may want to change the above filename variable to varname so that it is clear that a variable named whatever is being loaded rather than a file.
Más respuestas (1)
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!