Setting the distance between 2 lines?
7 views (last 30 days)
Show older comments
So I'm making a GUI, and I have used MatLab's example code with the timer. My goal was to create a line that moves across the display and you can change it's width, transparency, color, upper limit (to change the amount that has to be travelled), and the backgrounds color while the line moves, while it's live.
I got that to work, but now i wanna add another line (Note i am using xline) that i can add the same changes and they both change at the same time. getting that to happen wasn't hard, however I want there to be a distance between the two lines depending on the width i give it.
I.E: i make the first line 10 px, i want the second line to be 10 px as well, however I want there to be a distance between the 2 edges of the lines that are also 10 px.
I can change the size of xline but it is plotted dead in the center of the line, so the two lines overlap when i make the width like 100 px, so if both lines are 10 px, then the distance between the 2 lines have to be 20 px.
I want to write something that as i update the width, the position of the second line also changes to keep the lengths the same.
Note that I ultimately wanna be able to make more lines as well that follow the same idea (to create OKN stripes).
what is the best way to have my GUI automatically edit the distance automatically as i change the width of the lines?
0 Comments
Answers (1)
darova
on 19 Sep 2019
What about for loop?
width = 10;
dist = 10;
x0 = 0;
hold on
for i = 1:4
xline(x0+(width+dist)*i,'Linewidth',width)
end
hold off
Success
2 Comments
darova
on 20 Sep 2019
What about patch()?
width = 10;
height = 10;
x = [0 1 1 0]*width;
y = [0 0 1 1]*height;
cla
hold on
for i = 1:5
patch(x + 2*i*width,y,'k')
end
hold off
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!