フィルターのクリア

How to divide a line into several parts and obtain the coordinates?

16 ビュー (過去 30 日間)
Martha
Martha 2014 年 8 月 21 日
コメント済み: Martha 2014 年 8 月 21 日
Hi, I want to create a small script that can allow me to divide a line into segments and then retrieve me the coordinates of the new points. The line is vertical so I only need the 'y' values. I create the following, but I don't know how to make the scrip save me all the results of the loop in one matrix, it just save me the last one. Here is the script:
B=[9 3]; % first point
E=[9 10]; % second point
BE=E(2)-B(2); % distance between the two points in y
No_lam=input('Enter # of laminas:');
l=BE/No_lam;
Bi=(B(2))-l;
New=[];
for n=0:No_lam
Bi=[Bi+l]
end
I will appreciate some help with this. Martha

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 8 月 21 日
Martha - I think that you have the write idea with your initialization of New, you just have to put it to use. Rather than New create a variable called coords as
coords = zeros(No_lam+1,1);
The above adds one to the No_lam since the subsequent for loop iterates from zero to No_lam (so No_lam + 1 points). The for loop changes just by adding a single line
for n=0:No_lam
Bi=[Bi+l];
% save Bi to the vector of coords
coords(n+1) = Bi;
end
At the end of the loop, coords contains all values from 3 to 10.
---------
Since all of your elements of coords are evenly spaced, then an alternative to the above code is to use the linspace function which will generate a vector of linearly spaced elements between two points
coords = linspace(B(2),E(2),No_lam+1)';
The result will be identical to that produced with the for loop, just simplified considerably.
Try the above and see what happens!
  1 件のコメント
Martha
Martha 2014 年 8 月 21 日
Thanks Geoff, now I have three ways to do it...

サインインしてコメントする。

その他の回答 (1 件)

Iain
Iain 2014 年 8 月 21 日
This roughly what you're looking for?
for i= 1:number_of_iterations
B(i) = Bi + i*l;
end

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by