Hello! Help adjust the slider for the chart of the marshout (path) of the machine
function SliderValueChanged(app, event)
app.Slider = app.Slider.Value;
end
function GPSMenuSelected(app, event)
gps1=[app.x;app.y];
plot(app.UIAxes,app.x,app.y,'LineWidth',2);
hold on
plot(app.UIAxes,app.x( app.Slider ),app.y(app.Slider ),'b--o',...
'LineWidth',6)
hold off
end
I use hold on but when I try to use the slider I get an error
Array indices must be positive integers or logical values.
Error in OperatorMachine01/GPSMenuSelected (line 671)
plot(app.UIAxes,app.x( app.Slider ),app.y(app.Slider ),'b--o',...
Error using matlab.ui.internal.controller.WebMenuController/fireActionEvent (line 67)
Error while evaluating Menu Callback.

 채택된 답변

Geoff Hayes
Geoff Hayes 2020년 5월 15일

1 개 추천

Lev - why in your SliderValueChanged callback are you overwriting the Slider with its value? I suggest that you remove this function (or at least the code inside of it)
function SliderValueChanged(app, event)
% app.Slider = app.Slider.Value; % <----- this isn't necessary and is dangerous!
end
As for the error, it is telling you that you are trying to index into an array with something other than a positive integer or (0 or 1) logical value. I suspect that the slider value is NOT an integer so you will need to ask your self how to convert this number into a valid index for the arrays. For example, your code might look like
function GPSMenuSelected(app, event)
gps1=[app.x;app.y];
plot(app.UIAxes,app.x,app.y,'LineWidth',2);
hold on
sliderValue = ceil(app.Slider.Value); % <--- round up to the nearest integer
if sliderValue >= 1 && sliderValue <= length(app.x)
plot(app.UIAxes,app.x(sliderValue),app.y(sliderValue),'b--o',...
'LineWidth',6);
end
hold off
end
I don't know if that is valid for you so please validate before trying it out.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

태그

질문:

2020년 5월 15일

답변:

2020년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by