Setting the distance between 2 lines?

조회 수: 6 (최근 30일)
BMEenthusiast
BMEenthusiast 2019년 9월 19일
댓글: darova 2019년 9월 20일
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?

답변 (1개)

darova
darova 2019년 9월 19일
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
BMEenthusiast
BMEenthusiast 2019년 9월 19일
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 2019년 9월 20일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by