2011-02-21 5 views
0

私は初心者ですから、ここで皆本当にmatlabを手伝ってください。今私はmatlabのguiについて少し知っています。質問があります。私はGUIと保存ボタンの数字を持っています。私はこのコーディングをしました:ユーザーはgui(結果)を他のフォルダに保存する方法を教えてください。

filename = inputdlg('Please enter the name for your figures'); 

extensions = {'fig','bmp'}; 

for k = 1:length(extensions 

saveas(gcf, filename{:}, extensions{k}) 

set(gcf,'PaperPositionMode','auto') 

end 

これは私のguiのフォルダに保存することができます。どのように私はユーザーが彼は.bmgファイル内のGUIを保存するフォルダを選択できるようにしたいですか?

私は@gnovice提案から編集として、このコーディングを使用します。

filename = inputdlg('Please enter the name for your figures'); 

extensions = {'fig','bmp'}; 

directoryName = uigetdir; %# Open directory-selection dialog 

if directoryName == 0  %# User pressed the "Cancel" button... 

    directoryName = '';  %# ...so choose the empty string for the folder 

end 

saveas(gcf,fullfile(directoryName,fileName),extension); %# Save to the folder 

set(gcf,'PaperPositionMode','auto') 

しかし、このエラーが発生しました:あなたは上記のそれを使用するので

??? Error while evaluating uipushtool ClickedCallback 

??? Undefined function or variable 'fileName'. 

Error in ==> fyp_editor>uipushtool9_ClickedCallback at 1605 
saveas(gcf,fullfile(directoryName,fileName),extension); %# Save to the folder 

Error in ==> gui_mainfcn at 96 
     feval(varargin{:}); 

Error in ==> fyp_editor at 42 
    gui_mainfcn(gui_State, varargin{:}); 

Error in ==> 
@(hObject,eventdata)fyp_editor('uipushtool9_ClickedCallback',hObject,eventdata,guidata(hObject)) 


??? Error while evaluating uipushtool ClickedCallback 
+0

エラーが発生します。下の私の例では、キャメルケースでは 'fileName'という名前を使用していますが、' filename'はすべて小文字で使用しています。 – gnovice

答えて

4

あなたは明らかにすでに(INPUTDLGダイアログボックスについて知っています)、私はあなたがUIGETDIRダイアログボックス(またはそれに関してはany of the others)にも遭遇していないことに驚いています。自動的に特定のプラットフォームに必要なfile separatorsの世話をする私は、ファイルのパスを構築する機能FULLFILEを使用

fileName = inputdlg('Please enter the name for your figures'); 
directoryName = uigetdir('','Please select a folder to save to'); 
if directoryName == 0  %# User pressed the "Cancel" button... 
    directoryName = '';  %# ...so choose the empty string for the folder 
end 
filePath = fullfile(directoryName,fileName{1}); %# Create the file path 
extensions = {'fig','bmp'}; 
for k = 1:length(extensions) 
    saveas(gcf,filePath,extensions{k}); %# Save the file 
    set(gcf,'PaperPositionMode','auto'); 
end 

注:あなたはそうのように、ユーザーの閲覧を聞かせてフォルダを選択するためにこれを使用することができます。

+0

ディレクトリ名== 0は、上記のエラーが表示されるので機能していないと思います。 – raymond

関連する問題