How to define a path in saveas command?

83 visualizzazioni (ultimi 30 giorni)
M G
M G il 6 Ott 2011
Commentato: Jan il 30 Ago 2021
Hey Matlab users,
I've got a problem in defining a path for saveas command. When i want to save my Figure, the file is directly been saved in a path that is already on top of the command window in front of the "Current Folder". I tried to change the address by fname:
fname = 'D:\path1\path2';
saveas(gca,filename,'jpeg');
But it didn't work!!!
I very much appreciate your hint :) Mehdi

Risposta accettata

Jan
Jan il 6 Ott 2011
You have to consider the variable fname in the call of saveas:
fname = 'D:\path1\path2';
saveas(gca, fullfile(fname, filename), 'jpeg');
I assume "fpath" would be more meaningful than "fname".
  7 Commenti
Marcus Tan
Marcus Tan il 29 Ago 2021
Currently the saving is only saving .eea file. what i trying to do in this project is trying to plot the signals from .eea file format transform them to fig file format then i trying to save the fig file format to .bmp. Kindly advise. Thank you
Jan
Jan il 30 Ago 2021
...
for i=1:length(file_list)
filename = file_list{i}; % Now filename contains the .eea extension.
... % Your code
FolderName = 'C:\Users\Acer\Desktop\FYP 2021\Matlab (Proj)\Channels Split (STFT)\Schizophrenia (Combine Channels)';
[~, file] = fileparts(filename); % Remove extension
saveas(gca, fullfile(FolderName, [file, '.bmp']); % Append .bmp
end

Accedi per commentare.

Più risposte (1)

Wayne King
Wayne King il 6 Ott 2011
You can either change directory to the directory you want to save it in, or you can specify the directory
plot(randn(100,1));
save(gca,'c:\figures\test','jpeg');
  2 Commenti
Wayne King
Wayne King il 6 Ott 2011
Also if you want to define your figures directory
figuresdir = 'D:\figures\';
saveas(gcf,strcat(figuresdir, 'filename'), 'jpeg');
adams13
adams13 il 12 Gen 2021
Instead of 'strcat' it is better to use the 'fullfile' function because it will handle the file separator and will work in different operating systems (will place correctly '\' in Windows, '/' in Linux etc.)
saveas(gcf, fullfile(figuresdir, 'filename'), 'jpeg');

Accedi per commentare.

Categorie

Scopri di più su EEG/MEG/ECoG in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by