slider for march chart
조회 수: 1 (최근 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.
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!