problem with IF ELSE in push button GUI

조회 수: 7 (최근 30일)
Akshaya
Akshaya 2013년 1월 24일
hi
i'm trying to creat a gui. i'm stuck in a push button
function dft_pushbutton2_Callback(hObject, eventdata, handles)
if handles.current_data==handles.JEEP
filename='jeep1.wav';
else filename='bmwsuv1.wav';
end
[x sr1] = wavread(filename);
J = fft(x(1:1024));
f1 = linspace(0, sr1, length(J));
plot(f1(1:end/2+1), abs(J(1:end/2+1)))
what is wrong here ??? i'm not getting it..help
the problem is the else part doesn't work. if i swap only one works. i've a pop up menu with BMW and JEEP.push button for plotting signal works but push button for dft plotting doesn't.
  댓글 수: 3
Image Analyst
Image Analyst 2013년 1월 25일
You have
handles.current_data=handles.BMW;
and you had:
handles.BMW=b;
which means handles.BMW and handles.current_data are both numerical arrays. So how could handles.current_data ever equal a string 'BMW'? One's a double array, and ones a character array.
Walter Roberson
Walter Roberson 2013년 1월 25일
And also the code has two statements,
handles.current_data=handles.BMW;
handles.current_data=handles.JEEP;
so handles.current_data would be overwritten after being set to BMW

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

답변 (1개)

Image Analyst
Image Analyst 2013년 1월 24일
What are handles.current_data, and handles.JEEP? Are those integer values you assigned? floating point numbers you assigned? strings you assigned? or tag properties of controls in your GUI? It matters. If they're strings you need to compare with strcmpi(). If they're numbers (even handles), we need to know how they were assigned.
  댓글 수: 1
Akshaya
Akshaya 2013년 1월 24일
thank you .... ho i'm totally new to gui ... the program without the gui works fine. this is what i declared in open func.
[b sr1] = wavread('bmwsuv1.wav');
handles.BMW=b;
[j sr1] = wavread('jeep1.wav');
handles.JEEP=j;
handles.current_data=handles.BMW;
handles.current_data=handles.JEEP;
% Choose default command line output for Car_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
i don't know how to use compare

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

카테고리

Help CenterFile Exchange에서 Language Support에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by