plot([x1,x2],[y1,y2]) what does this mean ?

x0 = [0 100 0 0 0 0 ]; x1 = [0 100 86.60 50 -50 -86.60]; y0 = [0 0 0 0 0 0]; y1 = [100 0 50 86.60 86.60 50];
for i=1:length(x0);
hold on;
plot([x0(i),x1(i)],[y0(i),y1(i)])
end

Answers (1)

Chirag - that line of code
plot([x0(i),x1(i)],[y0(i),y1(i)])
is using the square brackets to concatenate two elements together to create (two) 1x2 arrays. These arrays, or coordinates, are then used to plot a line with an origin of (x0(i),y0(i)) and an end point of (x1(i),y1(i)). Put a break point at this line and run the above code. When the debugger pauses at this line, look at the inputs (coordinates) and see how they are used to draw the line on the figure for each iteration of the loop.

Categories

Tags

Asked:

on 7 Mar 2016

Answered:

on 7 Mar 2016

Community Treasure Hunt

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

Start Hunting!