我在matlab中读取dxf文件并获得此结构。如何保护名称与图层名称相同的separeted矩阵中的所有坐标。我的意思是
基准面1 = [ 10.8031269501964,2.06417715317460,5,3.70163846035642,2.06417715317460,5; ...]
数据
行= {[10.8031269501964,2.06417715317460,5,3.70163846035642,2.06417715317460,5], '基准面1'; [3.70163846035642,2.06417715317460,5,3.70163846035642,2.06417715317460,0], '基准面1'; [3.70163846035642,2.06417715317460,0,10.8031269501964 ,2.06417715317460,0], '基准面1'; [10.8031269501964,7.75770563520633,5,10.8031269501964,7.75770563520633,0], 'Plane4'; [10.8031269501964,2.06417715317460,5,10.8031269501964,2.06417715317460,0], '基准面1'; [3.70163846035642,7.75770563520633 ,5,10.8031269501964,7.75770563520633,5], 'Plane4'; [10.8031269501964,7.75770563520633,0,3.70163846035642,7.75770563520633,0], 'Plane4'; [3.70163846035642,7.75770563520633,5,3.70163846035642,7.75770563520633,0], 'Plane4'; [10.8031269501964,7.75770563520633,5,10.8031269501964,7.75770563520633,0], 'Plane3'; [10.8031269501964,2.06417715317460,5,10.8031269501964,2.06417715317460,0], '基准面1'; [3.70163846035642,7.75770563520633,2.50000000000000,3.70163846035642,7.75770563520633,1.14583181629325] 'Plane3'; [3.70163846035642,2.06417715317460,2.50000000000 000,8.19164033348243,2.06417715317460,2.50000000000000], '基准面1'; [8.19164033348243,2.06417715317460,2.50000000000000,8.19164033348243,2.06417715317460,1.14583181629325], '基准面1'; [8.19164033348243,2.06417715317460,1.14583181629325,3.70163846035642,2.06417715317460,1.14583181629325], '基准面1'; [ 3.70163846035642,2.06417715317460,5,3.70163846035642,2.06417715317460,2.50000000000000], '基准面1'; [3.70163846035642,7.75770563520633,1.14583181629325,3.70163846035642,7.75770563520633,0], 'Plane3'; [8.19164033348243,7.75770563520633,2.50000000000000,3.70163846035642,7.75770563520633,2.50000000000000],” Plane3 '; [3.70163846035642,7.75770563520633,5,10.8031269501964,7.75770563520633,5],' Plane3 '; [10.8031269501964,7.75770563520633,0,3.70163846035642,7.75770563520633,0],' Plane3' ; [3.70163846035642,7.75770563520633,1.14583181629325,8.19164033348243,7.75770563520633, 1.14583181629325], 'Plane3'; [8.19164033348243,7.75770563520633,1.14583181629325,8.19164033348243,7.75770563520633,2.50000000000000], 'Plane3'; [3.70163 846035642,7.75770563520633,5,3.70163846035642,7.75770563520633,2.50000000000000], 'Plane3'; [10.8031269501964,7.75770563520633,5,10.8031269501964,7.75770563520633,0], '计划2'; [10.8031269501964,7.75770563520633,5,10.8031269501964,2.06417715317460,5],”计划2 '; [10.8031269501964,2.06417715317460,0,10.8031269501964,7.75770563520633,0],' 计划2 '; [10.8031269501964,2.06417715317460,5,10.8031269501964,2.06417715317460,0],' 计划2' ; [3.70163846035642,7.75770563520633,5,3.70163846035642,2.06417715317460, 5], 'Plane4'; [3.70163846035642,2.06417715317460,5,3.70163846035642,2.06417715317460,0], 'Plane4'; [3.70163846035642,2.06417715317460,0,3.70163846035642,7.75770563520633,0], 'Plane4'; [3.70163846035642,7.75770563520633,0, 3.70163846035642,7.75770563520633,5], 'Plane4'; [3.70163846035642,2.06417715317460,5,3.70163846035642,7.75770563520633,0], 'Plane4'; [3.70163846035642,7.75770563520633,5,3.70163846035642,2.06417715317460,0], 'Plane4'; [3.70163846035642, 4.91094139419046,2.50000000000000,3.70163846035642,4.9109413941904 6,0], 'Plane4'; [3.70163846035642,4.91094139419046,0,3.70163846035642,2.06417715317460,2.50000000000000], 'Plane4'; [3.70163846035642,2.06417715317460,2.50000000000000,3.70163846035642,4.91094139419046,5], 'Plane4'; [3.70163846035642,4.91094139419046, 5,3.70163846035642,7.75770563520633,1.82291590814662], 'Plane4'; [3.70163846035642,7.75770563520633,1.82291590814662,3.70163846035642,4.91094139419046,0], 'Plane4'; [10.8031269501964,7.75770563520633,5,8.19164033348243,7.75770563520633,2.50000000000000], 'Plane3'; [ 8.19164033348243,7.75770563520633,2.50000000000000,8.19164033348243,7.75770563520633,1.14583181629325], 'Plane3'; [8.19164033348243,7.75770563520633,1.14583181629325,10.8031269501964,7.75770563520633,0], 'Plane3';}
答案 0 :(得分:3)
不使用eval
将变量用作名称(这会导致其他问题),您可以考虑将结构拆包到一个可以自动生成的结构中......
VectorLength=6; % length of the vectors in the input
names=unique(Line(:,2));
for ii=1:length(names);
nameLocations=strcmp(Line(:,2),names{ii});
LineStruct.(names{ii})=...
reshape([Line{nameLocations,1}],sum(nameLocations),VectorLength);
end
给出了
LineStruct =
Plan2: [4x6 double]
Plane1: [9x6 double]
Plane3: [12x6 double]
Plane4: [15x6 double]
可以通过调用结构的字段来使用矩阵,例如LineStruct.Plane1
答案 1 :(得分:2)
以下是您一次只能在一架飞机上完成的方法。它当然可以自动化,但是如果你有很多飞机,你可能不会想要这样做:
Plane1 = Line(strcmp(Line(:,2),'Plane1'),1);
Plane1 = vertcat(Plane1{:})