Prev: Question about nonlinear programming fmincon
Next: Is it possible to refresh xy graph in realtime windows target
From: Mano Samuel on 18 Jul 2010 22:28 Hello, I have a following loop in a GUI written programmatically with two push buttons, namely, save and delete. Say I have a ten .wav files. I read each wave file and store the data in a variable. so, the program begins with, files=dir('*.wav'); under the main function followed by a for loop. for n = 1:length(files); % Here I start by plotting the first wave file. plot(mydata,'b') % after the first wave file is plotted, I want MATLAB to pause/stop here % At this point, I want the user to be able to carry out a certain number of operations on the wave file for which I have written codes already. % if the user wishes to retain the wav file, he presses the "save" button, otherwise , he presses the delete button. My question is, how do I get to pause/stop the program at this point and then come back to this point again after the user chooses either to delete or save the wave file end Any help will me much appreciated. thank you
From: neil on 19 Jul 2010 00:15 "Mano Samuel" <manosamuel(a)rediffmail.com> wrote in message <i20d7k$pqn$1(a)fred.mathworks.com>... > > Hello, > > I have a following loop in a GUI written programmatically with two push buttons, > namely, save and delete. > > Say I have a ten .wav files. I read each wave file and store the data in a variable. > > so, the program begins with, > > files=dir('*.wav'); > > under the main function followed by a for loop. > > for n = 1:length(files); > > % Here I start by plotting the first wave file. > > plot(mydata,'b') > > % after the first wave file is plotted, I want MATLAB to pause/stop here > % At this point, I want the user to be able to carry out a certain number > of operations on the wave file for which I have written codes already. > % if the user wishes to retain the wav file, he presses the "save" button, > otherwise , he presses the delete button. > > My question is, how do I get to pause/stop the program at this point and then > come back to this point again after the user chooses either to delete or save > the wave file > > end > > Any help will me much appreciated. thank you I'm pretty sure there might be a better way to do this. But here is a possible way function [ ] = mywavimporter( ) figH = figure; setappdata(figH,'saveFile',true); uicontrol('parent',figH,'style','pushbutton','string','save','callback',@(obj,evt)btnSaveCallback(obj,evt)) files=dir('*.wav'); for n = 1:length(files); uiwait(figH); if (getappdata(figH,'saveFile')) %save file code else %Delete file code end end end function btnSaveCallback(varargin) setappdata(get(varargin{1},'parent'),'saveFile',true); uiresume(get(varargin{1},'parent')); end
From: Mano Samuel on 19 Jul 2010 02:55
"neil " <neil.iain(a)gmail.com> wrote in message <i20jgq$ko2$1(a)fred.mathworks.com>... > "Mano Samuel" <manosamuel(a)rediffmail.com> wrote in message <i20d7k$pqn$1(a)fred.mathworks.com>... > > > > Hello, > > > > I have a following loop in a GUI written programmatically with two push buttons, > > namely, save and delete. > > > > Say I have a ten .wav files. I read each wave file and store the data in a variable. > > > > so, the program begins with, > > > > files=dir('*.wav'); > > > > under the main function followed by a for loop. > > > > for n = 1:length(files); > > > > % Here I start by plotting the first wave file. > > > > plot(mydata,'b') > > > > % after the first wave file is plotted, I want MATLAB to pause/stop here > > % At this point, I want the user to be able to carry out a certain number > > of operations on the wave file for which I have written codes already. > > % if the user wishes to retain the wav file, he presses the "save" button, > > otherwise , he presses the delete button. > > > > My question is, how do I get to pause/stop the program at this point and then > > come back to this point again after the user chooses either to delete or save > > the wave file > > > > end > > > > Any help will me much appreciated. thank you > > I'm pretty sure there might be a better way to do this. But here is a possible way > > function [ ] = mywavimporter( ) > > figH = figure; > setappdata(figH,'saveFile',true); > > uicontrol('parent',figH,'style','pushbutton','string','save','callback',@(obj,evt)btnSaveCallback(obj,evt)) > files=dir('*.wav'); > > for n = 1:length(files); > > uiwait(figH); > if (getappdata(figH,'saveFile')) > %save file code > else > %Delete file code > end > > end > > end > > > function btnSaveCallback(varargin) > setappdata(get(varargin{1},'parent'),'saveFile',true); > uiresume(get(varargin{1},'parent')); > end Thanks neil. it works. having started designing GUIs pretty recently, my GUI programs are still rusty. I have to find ways to make them quicker and more efficient. |