Producing lines from a matrix of coordinates and length
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Image Analyst
2017 年 4 月 7 日
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.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!