How can I use guidata to pass 2 different variables in 2 different callbacks of a GUI?

1 view (last 30 days)
My GUI is required to-
Browse for .mat and .wav files. Store the file names in storedStructure and storedStructure1.
Use load and wavread in seperate callbacks and plot those 2 functions.
Upon loading the .wav file, I plotted it without any problems. But there are problems with the .mat file.
Here's my code:
startingFolder = 'C:\Users\Mayank\Desktop\Matlab';
% Get the name of the mat file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.mat');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a mat file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName);
storedStructur = fullFileName;
handles.b = storedStructur;
guidata(hObject,handles);
axes(handles.Sensor);
ema = load(handles.b);
plot(ema);
The error being-
Error using plot
Not enough input arguments.
Error in Speech_Proc>pushbutton10_Callback (line 149)
plot(ema);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Speech_Proc (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Speech_Proc('pushbutton10_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

Accepted Answer

Walter Roberson
Walter Roberson on 30 Dec 2013
When you load() a .mat file, the result is a structure with fields named after the variables stored in the file. When you plot() you need to specify which field to plot. For example if what was stored in the .mat file was a variable named "sound_data", then you would
plot(ema.sound_data);

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!