Slider Code problem with axes
显示 更早的评论
this an example of a slider to control movement on axes
a = get (handles.slider2,'Value')
x = 0:0.1:50;
y = sin (x*a);
plot (handles.axes1,x,y)
and this me trying to apply the example
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (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
clc;
load ('100m.mat')
a = get(handles.slider2,'Value');
x = 0:0.1:50;
ECGsignal = (val - 1024 )/200;
y = ECGsignal*x*a;
plot (handles.axes1,x,y)
what is the problem in my code ?
4 个评论
Yair Altman
2019-2-16
You need to clarify exactly why you think that the result is not as expected. In other words, why do you think there is any problem?
Hassan Bosha
2019-2-16
Rik
2019-2-18
If you want to scroll through your data, why don't you use the Value property of the slider to change the XLim property of your axes object?
Hassan Bosha
2019-2-19
采纳的回答
更多回答(1 个)
Yair Altman
2019-2-17
In your example, both val and x are not scalars. When you multiply vectors/matrices in Matlab using the * operator, Matlab uses linear algebra rules to multiply the data. This causes an error because the two variables do not match in their size as required by linear algebra multiplication rules (that the number of rows in one multiplicant is equal to the number of columns in the other).
What you probably wanted to do instead was to multiple each element of val by the corresponding element in x (assuming that they are both vectors of the same size) - this is done with element-wise multiplication (.*) :
y = ECGsignal.*x*a;
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

