How to change output of matlabatch result in spm25

12 visualizaciones (últimos 30 días)
悠飛
悠飛 el 30 de Sept. de 2025 a las 0:22
Respondida: Konrad el 30 de Sept. de 2025 a las 9:01
Here is explaing we can change save path, but it doesn't tell me how to chage as detail in
  1 comentario
Torsten
Torsten el 30 de Sept. de 2025 a las 0:42
Editada: Torsten el 30 de Sept. de 2025 a las 0:43
AI Overview
To change where MATLAB saves files, either specify the desired folder directly in the save command using fullfile(folder, filename) or use the uiputfile function to interactively select a folder and filename when saving. You can also change the default working directory through the "Preferences" menu by setting an "Initial working folder" or manage the MATLAB path for function access, but these methods affect the MATLAB search path, not the default save location for data files.
Method 1: Specify the save path directly in the save command
This method is best for saving a single file to a specific location without user interaction.
  1. Use the fullfile function: to create the full path to your file.
  • folder = 'C:\path\to\your\folder'; % Define your desired folder
  • filename = 'mydata.mat'; % Define the desired filename
  • fullFileName = fullfile(folder, filename);
  1. Use the save command: with the fullFileName.
  • save(fullFileName, 'variable_to_save');
Code
% Example of saving a variable to a specific folder
folder = 'C:\Users\Documents\MATLAB\MyProject';
filename = 'my_data.mat';
myVariable = 1:10; % Your variable to save
% Ensure the folder exists (optional, but good practice)
if ~exist(folder, 'dir')
mkdir(folder);
end
fullFileName = fullfile(folder, filename);
save(fullFileName, 'myVariable');
Method 2: Use uiputfile for interactive selection
This method provides a graphical user interface (GUI) for the user to choose the save location and filename.
  1. Call the uiputfile function: to open a dialog box for the user to specify a file.
  • [filename, pathname] = uiputfile({'*.mat','MAT-files (*.mat)'; '*.*','All Files (*.*)'},'Save File As');
  1. Construct the full file path: using the returned pathname and filename.
  • fullFileName = fullfile(pathname, filename);
  1. Save the file: using the fullFileName.
  • save(fullFileName, 'variable_to_save');
Code
% Example of using uiputfile to select where to save
myVariable = 1:10; % Your variable to save
[filename, pathname] = uiputfile({'*.mat','MAT-files (*.mat)'; '*.*','All Files (*.*)'},'Save File As');
if filename ~= 0 % User did not cancel
fullFileName = fullfile(pathname, filename);
save(fullFileName, 'myVariable');
end
Note on changing the MATLAB path:
The path and savepath commands and the "Set Path" dialog box in MATLAB are used to manage the search path, which is where MATLAB looks for functions and scripts. While this is important for running your code, it is a different function from where MATLAB defaults to saving files

Iniciar sesión para comentar.

Respuestas (1)

Konrad
Konrad el 30 de Sept. de 2025 a las 9:01
If you want to save a batch in SPM as an .m-script file instead of a .mat file, just select the .m file type in the "save job as..." dialog.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by