How do I save multiple dynamically generated variables to the same .mat file?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ruikai Tang
el 21 de Mayo de 2021
Comentada: Ruikai Tang
el 25 de Mayo de 2021
A dataset I'm working with makes my computer run out of ram when I try to process the entire thing at once, so I'm trying to process it once cell at a time and save that to a file to prevent a ram shortage. I think my problem is not understanding the proper syntax of the save() function in regards to dynamically generated variable names. The cut down code is below:
for x = 1 : rowLim
for y = 1 :colLim
param(x,y,:) = S1_PParam(C11(x, y), C22(x, y), C12_real(x, y), C12_imag(x, y));
save([path '\output.mat'], 'param(x,y,:)', '-append');
end
end
where rowLim and colLim denote the size of the file I'm working with, and S1_PParam is a custom function that returns a 1 by 1 by 27 array when called with the input parameters shown. I'm currently getting a "param(x,y,:)' is not a valid variable name" error, but I have no idea what the correct variable name would be in this case.
The ideal output would be a single variable in the .mat file that encompasses the entire dataset (e.g. a variable that is a rowLim by colLim by 27 array), but given that seems impossible given how the save() function works I'm just trying to get the output to be a .mat file containing separate 1 by 1 by 27 arrays for each cell in the dataset.
2 comentarios
Respuesta aceptada
Walter Roberson
el 21 de Mayo de 2021
You cannot use save to save part of a variable, except that if you have a scalar struct and you want to save fields as complete variables then you can select the fields to save.
Perhaps matfile would be uuseful to you. If not then you will need to store into variables and save the variables.
3 comentarios
Walter Roberson
el 25 de Mayo de 2021
m = matfile('output.mat','Writable',true);
for x = 1 : rowLim
for y = 1 :colLim
s1p = S1_PParam(C11(x, y), C22(x, y), C12_real(x, y), C12_imag(x, y));
m.param(x,y,1:length(s1p)) = s1p;
end
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Workspace Variables and MAT Files 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!