slider for march chart

2 次查看(过去 30 天)
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by