save button condition?
Mostrar comentarios más antiguos
Hi i have created a gui in MATLAB. now i want to put validation on the save button such that when the user saves and if the name already exists then he should be prompted to change!How can i do this?
Respuestas (2)
Matt Fig
el 2 de Mayo de 2011
You don't mention what it is that you are protecting, a variable or file for example, so I will speak generally.
R = get_name_user_wants;
while exists_R
Tell_user_this_already_exists;
R = get_name_user_wants;
end
Where get_name_user_wants is your method of getting the information from the user, like a dialog box or examining the string of a uicontrol. exists_R is your method of checking, depending on what it is you are trying to save. Here I imagine you will want to use the EXIST function in some way. Tell_user_this_already_exists is your way of notifying the user that the name already exists. This could involve a warn dialog or setting the string in the uicontrol to a red message for a second, etc....
%
%
%
%
EDIT In response to your 'answer' below.
What is 'exists_image' in your code? I said above that you will want to use the EXIST function.
button = questdlg('Do you want to save the changes?')
if strcmp('Yes',button)
% image =(IMG) %define a 8-bit unsigned integer.
[filename,pathname] = uiputfile({'*.jpg', 'JPEG Image File'; ...
'*.*', 'All Files (*.*)'}, ...
'Save current image as');
while exist(filename,'file')
uiwait(errordlg(['File already exists!',...
' Choose another Name.'],'!Error!'));
[filename,pathname] = uiputfile({'*.jpg', 'JPEG Image File'; ...
'*.*', 'All Files (*.*)'}, ...
'Save current image as');
end
% Here is where you save with filename!
end
Also note that, unless this functions is a nested function to a function which has defined IMG, there will exist no variable named IMG, so the line referencing IMG will error. That is why I commented it out. Another thing which you should take care to change: Your callback is named SAVE. But this is a built-in MATLAB function. Therefor, your callback will mask the built-in function so that you will not be able to use MATLAB SAVE anywhere in the scope of your function..
However, your question pertaining to the filename has been answered.
1 comentario
researcher
el 3 de Mayo de 2011
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!