GUI - Trim vector according to slider positions

Hello
I have created a GUI with two sliders and one button. Now I want to use the slider positions to trim a data vector. I tried the following way, but I didn´t work...
My attempt: I changed the slider callback function in a way that a output (hS1) is created. Where hS1 is the slider position.
% --- Executes on slider movement.
function [hS1]=slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
load Data.mat
x=get(hObject,'value');
x_round=round(x)
set(hObject,'value',x_round);
y=(L_KnieAngle3D_orig(x_round,1));
line(x_round,y,'linestyle','none','marker','o','markeredgecolor','r');
hS1=x_round
I did the same with slider Nr. two. As next step I changed the callback function of the pushbutton and added the hS1&hS2 to the input parameters.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hS1, hS2, hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
load Data.mat
Datavector_new=Datavector_orig(hS1:hS2);
assignin('base','Datavector_new',Datavector_new);
But when I click the pushbutton I only get an empty matrix.
Datavector_new =
Empty matrix: 0-by-1
Does someone have an idea what´s going wrong?

Risposte (1)

Now I tried a second attempt.
I assigned the slider position to variables (x1,x2) in the workspace. Then I added the input variables x1,x2 and Datavector to the pushbutton1_Callback-function.
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
load Data.mat
x=get(hObject,'value');
x_round=round(x);
set(hObject,'value',x_round);
y=(L_KnieAngle3D_orig(x_round,1));
set(line,'xdata',x_round,'ydata',y);
line(x_round,y,'linestyle','none','marker','o','markeredgecolor','r');
x1=x_round
assignin('base','x1',x1);
The pushbutton-function should create an new vector, called Datavector_new, with the limits x1 and x2.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(x1, x2, Datavector, hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Datavector_new=Datavector(x1:x2)
assignin('base','Datavector_new',Datavector_new);
But now I get the message:
Datavector_new =
1x0 struct array with fields:
figure1
pushbutton1
text3
text1
slider2
slider1
axes1
output
Does someone have an idea what went wrong? Normally the "Datavector" should be shortened by the limits x1 and x2.

Categorie

Richiesto:

il 11 Ott 2012

Community Treasure Hunt

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

Start Hunting!

Translated by