function pushbutton_saveTest_Callback(hObject, ~, handles)
listboxItems = get(handles.listbox_tests,'String');
editedTestName = char(get(handles.edit_testName,'String'));
editedTest = getNewTest(handles,editedTestName);
currentFolderPath = pwd;
if ismember({'-Empty-'},listboxItems)
listboxItems{1,:} = editedTestName;
elseif ismember({editedTestName}, listboxItems)
choice = questdlg('Test already exists, do you want to overwrite?', ...
'Test already exists', ...
'default');
switch choice
case 'Yes'
fileName = [currentFolderPath '\Tests\' editedTestName];
case 'No'
answer = char(inputdlg({'Enter new test name'},'Save new test',1,{'untitled test'}));
fileName = [currentFolderPath '\Tests\' answer];
listboxItems(end+1,:) = {answer};
case 'Cancel'
fileName=[];
end
else
fileName = [currentFolderPath '\Tests\' editedTestName];
listboxItems(end+1,:) = {editedTestName};
end
if ~isempty(fileName)
save(fileName,'editedTest');
handles.tests = setfield(handles.tests, editedTestName, editedTest);
end
set(handles.listbox_tests,'String',listboxItems);
guidata(hObject, handles);
2 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/225435-save-variable-as-string-from-user-input#comment_294697
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/225435-save-variable-as-string-from-user-input#comment_294697
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/225435-save-variable-as-string-from-user-input#comment_295228
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/225435-save-variable-as-string-from-user-input#comment_295228
Sign in to comment.