How to pass string value from one callback function to another?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
0 votes
Accepted Answer
20 Comments
% --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles)
[filename,filepath]= uigetfile({'*.*';'*.wav';'*.m4a'});
fullname = fullfile(filepath, filename);
set(handles.edit6,'string', fullname);
% --- Executes on button press in button. function button_Callback(hObject, eventdata, handles) % hObject handle to button (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
fullname = get(handles.edit6, 'string');
data = audioread(fullname);
L= length (data);
Y= fft(data)
P2= abs (Y/L)
P1= P2(1:L/23+1);
P1(2:end-1)= 2*P1(2:end-1)
figure= subplot('position', [0.56, 0.15, 0.4, 0.3]);
K= plot (P1);
title ('Frequency Domain')
xlabel('f(Hz)')
ylabel('P1(f)')
hold on
[y,Fs]= audioread(fullname); t= linspace(0,length(y)/Fs, length(y));
figure1= subplot('position', [0.10, 0.15, 0.4, 0.3]);
plot(t,y);
title ('Time Domain')
xlabel('Time (sec)')
ylabel('Amplitude')
I am having a problem. when i get the back button in this .fig and come back and try to browse the .wav file, it does not set the fullname in the edit text box.
Put in a breakpoint at the uigetfile and step through to see what happens. For example is handles.edit6 still a valid handle at the time of the set() ? If the set() works without error then what do you get if you then (in the debugger)
get(handles.edit6, 'string')
this is error the message that I am getting..
Undefined function or variable 'button_DeleteFcn'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in multiply (line 43)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)multiply('button_DeleteFcn',hObject,eventdata,guidata(hObject))
Error using multiply>figure1_CloseRequestFcn (line 140) Error while evaluating UIControl DeleteFcn.
Dot indexing is not supported for variables of this type.
Error in multiply>pushbutton7_Callback (line 248) set(handles.edit6,'string', fullname);
Your uicontrol named button with string Train! has been configured to expect to be able to call button_DeleteFcn and button_KeyPressFcn but those do not exist.
Please make sure you are using my versions of the .fig and the .m . Close any existing figures and "clearvars"
The fix for the back button (which has already been written into that multipy.m) was
function pushbutton2_Callback(hObject, eventdata, handles)
back_to = 'SRS01_GUI_TrainPage.fig';
if exist(back_to, 'file')
open(back_to);
close('multiply');
else
waitfor(warndlg( sprintf('Cannot go back, did not find find "%s"', back_to)));
end
That is, the reason you were failing was that the "back" button was trying to invoke SRS01_GUI_TrainPage and that did not exist. The replacement code makes sure it exists before trying to invoke it.
More Answers (0)
Categories
Find more on Code Execution in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)