Hello everyone I'm the best rookie in MATLAB and I need help again.
So I want to plot selected item on listbox1
thats my codes
function listbox1_Callback(hObject, eventdata, handles)
axes(handles.axes1);
time= 1:5;
axess = get(handles, 'String');
signal = get(handles, 'Value');
axessignal = axess{signal};
plot(axessignal,time);
it will plot when user select an item on listbox1
I mean when user selects first item on listbox1 then axes1 will plot first item and user selects second item axes1 will plot it
all files are sound
by the way I'm getting this error when i try codes that i wrote up
Error using get
Conversion to double from struct is not
possible.

 채택된 답변

Emre Akinci
Emre Akinci 2019년 6월 7일

0 개 추천

code that you wrote shows me my listbox items
and when i examined hObjects it showed me properties of listbox1 string is selected file name

댓글 수: 3

Thanks Mr. Roberson for help. I found how to do it. There are codes
function listbox1_Callback(hObject, eventdata, handles)
axes(handles.axes1);
signal = hObject.Value;
axess = hObject.String;
axessignal = audioread(axess{signal});
time = (0:size(axessignal,1)-1)/44100;
plot(time, axessignal(:,1));
these codes are plotting sound files that selected from listbox1
Walter Roberson
Walter Roberson 2019년 6월 9일
Why do you assume 44100 when it is trivial to get the sampling frequency from the file?
You should avoid assuming that the files are in the current directory: you should be giving the user a choice of directories and you should record that choice. That is what the audiodir = handles.DirectoryOfAudioFiles; in my response was about.
Emre Akinci
Emre Akinci 2019년 6월 9일
you are right sir.
but it is not very important because we are providing useable audiofiles
all files fs are 44100 and in 100000x1 dimension

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 6월 7일

0 개 추천

function listbox1_Callback(hObject, eventdata, handles)
axes(handles.axes1);
time= 1:5;
axess = get(hObject, 'String');
signal = get(hObject, 'Value');
signal_name = axess{signal};
Now you have to load the data whose name is given by signal_name, and then plot it. For example,
audiodir = handles.DirectoryOfAudioFiles;
filename = fullfile(audiodir, [signal_name, '.wav']);
[data, FS] = audioread(filename);
time = (0:size(data,1)-1)/FS;
plot(time, data(:,1));

댓글 수: 6

Emre Akinci
Emre Akinci 2019년 6월 7일
I cant make it work and it is doing what I said?
Conversion to double from struct is not possible.
I get this error again
axess = get(hObject, 'String');
about that code
dbstop if error
and then run your code. When it stops, examine hObject : in your release it would be expected to disp in a format such as
UIControl with properties:
Show us the output of
which get(hObject)
dbstack
get is a built-in method % matlab.ui.control.UIControl method
> In bitti>listbox1_Callback (line 106)
In gui_mainfcn (line 95)
In bitti (line 43)
In matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)bitti('listbox1_Callback',hObject,eventdata,guidata(hObject))
I'm getting this when I wrote
which get(hObject)
dbstack
When you examined hObject, what showed up? The other information you provided suggests that you did see a UIControl but it is best to be sure.
When you are stopped at the error, what shows up if you try
axess = hObject.String
axess = hObject.String;
signal = hObject.Value;

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

제품

릴리스

R2017a

질문:

2019년 6월 7일

댓글:

2019년 6월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by