Effacer les filtres
Effacer les filtres

Producing lines from a matrix of coordinates and length

1 vue (au cours des 30 derniers jours)
Yesbol
Yesbol le 7 Avr 2017
Commenté : Yesbol le 8 Avr 2017
Hello.
I have a matrix
1 303.5642 157.0846 303.6792 154.5551 0 0 2.5321
2 303.6792 154.5551 303.7942 151.5658 0 0 2.9916
3 303.7942 151.5658 305.2889 146.0469 0 0 5.7177
4 305.2889 146.0469 306.5536 142.3677 0 0 3.8905
5 306.5536 142.3677 301.6096 140.2981 0 0 5.3597
6 301.6096 140.2981 299.0802 139.0333 0 0 2.828
7 299.0802 139.0333 297.0106 138.2285 0 0 2.2206
8 518.2249 225.1505 507.1871 230.3245 0 0 12.1902
9 507.1871 230.3245 505.0026 236.7631 0 0 6.7992
The first column represents number of line, columns 2 and 3 represent the coordinates of the start point of the line, columns 4 and 5 - end point. Column 8 represents the length of the line.
My task is to produce 2 text documents to be able to run power flow analysis. The first document contains the coordinates of all points. The format looks like:
1,303.5642,157.0846
2,303.6792,154.5551
3,303.7942,151.5658
The second document represents all lines and their lengths in a following format:
New Line.LINE1 Bus1=1 Bus2=2 phases=3 Linecode=4c_70 Length=2.5321 Units=m
New Line.LINE2 Bus1=2 Bus2=3 phases=3 Linecode=4c_70 Length=2.9915 Units=m
New Line.LINE3 Bus1=3 Bus2=4 phases=3 Linecode=4c_70 Length=5.7177 Units=m
New Line.LINE4 Bus1=4 Bus2=5 phases=3 Linecode=4c_70 Length=3.8905 Units=m
where 'Bus1' is the coordinates of a the start point of the line, and 'Bus2' - end point. 'Length=' is the length of the line.
Currently, I have following program:
% First part - Extracting the coordinates;
A=A;
B = sortrows([A(:, 1:3);
bsxfun(@plus, A(A(1:end-1, 4) ~= A(2:end, 2), [1, 4, 5]), [0.5, 0, 0])]); %any version
B(:, 1) = B(1, 1) + (0 : size(B, 1)-1);
csvwrite('XY_Position.txt', B);
% Second part - Producing line code
fileID2 = fopen('Lines.txt','w');
for i=1:342
arr='New Line.LINE%d Bus1=%d Bus2=%d phases=3 Linecode=4c_70 Length=%.4f Units=m\n';
fprintf(fileID2,arr,i,i,i+1,A(i,8));
end
fclose(fileID2);
The first part is working well because it extracts all coordinates needed. The problem is with the second part since it does not include all coordinates (because matrix A has less rows than matrix B, hence loop is limited) and it connects all the points (even those which are not supposed to be connected, for example, when there is a new line)
I'm stuck.
Your help is greatly appreciated.
Thank you
  2 commentaires
Image Analyst
Image Analyst le 7 Avr 2017
Please attach lines.txt. Then, for the first part, why can't you simply do
csvwrite('XY_Position.txt', A(:, 1:3)); % Extract out and write first 3 columns.
Yesbol
Yesbol le 8 Avr 2017
I'm attaching Lines.txt, XY_Positiont.txt, matrix A and script The first part checks whether the end of current point is equal to the start of next point. If true, it writes only 2 and 3 column (meaning that it is the same line) If false - it also writes column 4 and 5 (new line starts). It ensures that I won't lose points and I don't the same point repeated which is needed.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by