MATLAB Answers

please show me how to use 'line commander'

2 views (last 30 days)
상태 박
상태 박 on 26 Nov 2020
Commented: 상태 박 on 28 Nov 2020
hello!
i want to know how to use 'line commander'
Error: Value is not a numeric scalar value ( i wonder about this. x_p(1) = 3 x_p(2)= 2.9968 ... isn't it scalar value?)
u=line(x,y,'Color','k','LineWidth','2');
what is the matter?
in advance, person that answers my questiion. thank you!
for i=1:length(time) %length(time) =100
n2=fix(length(time)/n1); % n1=30
hold on
axis equal
x=[0 x_p(i)]; %x_p(i) is 100*1 matrix
y=[0 y_p(i)]; %y_p(i) is 100*1 matrix
u=line(x,y,'Color','k','LineWidth','2');
F(i)=getframe;
if(i==length(time))
break;
end
if(0==rem(i,n2))
else
delete(u)
end

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Nov 2020
u=line(x,y,'Color','k','LineWidth',2);

  4 Comments

Show 1 older comment
Image Analyst
Image Analyst on 26 Nov 2020
Yes, LineWidth is a number not a character. Here are a few more improvements.
numPoints = 100; % or length(time)
x_p = rand(numPoints, 1); % Or however you defined the.
y_p = rand(numPoints, 1);
n1 = 30;
hold on
axis equal
for k = 1 : numPoints %length(time) =100
n2=fix(numPoints/n1); % n1=30
% Get endpoints of the line into a 2 element vector.
x=[0, x_p(k)]; %x_p(i) is 100*1 matrix
y=[0, y_p(k)]; %y_p(i) is 100*1 matrix
% Call the line function to draw a black line.
u=line(x,y, 'Color','k', 'LineWidth', 2);
% Get the handle to the graphics in the axes.
F(k) = getframe;
if rem(k,n2) == 0
% Do something
else
% Delete the line we just drew.
delete(u)
end
end
Can you please Accept Walter's answer now to give him "reputation points"? Thanks in advance.
Walter Roberson
Walter Roberson on 26 Nov 2020
If you are going to draw a line and then erase it, then it is more efficient to instead create the line just once and to update its XData and YData properties the other times.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!