Problems creating a chart
이전 댓글 표시
Hello! I'm trying to create a graph and I have a problem
plot(Data','.-b')
ylabel('temp')
xlabel('time')
f = getframe;
hold on
plot(x1:x2,Data(x1:x2),'o-r')
ylabel('temp')
xlabel('time')
f = getframe;
plot(z,'o-g')
z=ceil(z);
plot(1:z,Data(1:z),'o-w')
ylabel('temp')
xlabel('time')
f = getframe;
hold off
x1 and x2 matrix 1x500 double
z 1x500 single
Error using :
Colon operands must be real scalars.
Error in Untitled (line 1601)
plot(1:z,Data(1:z),'o-w')
my goal is to animate temperature changes over time, x1 and x2 are areas where a person can work (represent the coordinates of the temperature), z is an area where you can’t work
댓글 수: 3
TADA
2019년 8월 26일
Apparently, when you use a double matrix the colon operator takes the first item in the matrix, but when you use a single it errors.
I would expect the same exception for double matrices as well.
I don't know if it is documented behavior or not, but it sure isn't good practiced code if you ask me.
In my opinion you will do well to use actual scalars for colon operator vector decleration
TADA
2019년 8월 26일
This should work like your other plots do
plot(x1(1):x2(1),Data(x1(1):x2(1)),'o-r');
plot(1:z(1),Data(1:z(1)),'o-w');
TADA
2019년 8월 26일
the documentation states that all colon operators parameters should be scalars.
You stumbled on some undocumented strange behavior. Better to use scalars in all your colon operations and be on the safe side
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!