Setting the distance between 2 lines?

1 vue (au cours des 30 derniers jours)
BMEenthusiast
BMEenthusiast le 19 Sep 2019
Commenté : darova le 20 Sep 2019
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?

Réponses (1)

darova
darova le 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
img.png
  2 commentaires
BMEenthusiast
BMEenthusiast le 19 Sep 2019
This solves my problem partially. I need the distance between lines to be the same as the width of the lines.
here is an idea of what it should look like:
Capture.JPG
where the width of the lines and the distance of the edges are the same. Thank you so much for showing me how to make more lines in one script easily! It will definitely help me with the GUI, but now I need to develop something that can make the distances the same.
darova
darova le 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by