如题
代码功能:
在之前写过2020版的CST画图处理的matlab程序,能够正常运行。但是版本升级后,2021版的画图文件格式变了,所以又得写新代码。(ノへ ̄、)
P.S.这次的代码比上次简约很多了,而且我感觉鲁棒性更强。
matlab 版本依然是是2021a,还是新版的matlab好用。不过写下来觉得python也许更适合?如果是老版的matlab估计要写很长吧。
matlab代码
filename = 'test.txt'; %CST导出的绘图文件的文件名
atext = readlines(filename); %读入文件
sa = atext;
indexa = regexp(atext, '.* .*', 'match');
ind = ~cellfun(@isempty, indexa);
index = find(ind==1);%获取索引
btext = atext(index);
indexa = regexp(btext, '#.*', 'match');
ind = ~cellfun(@isempty, indexa);
index = find(ind==1);%获取索引
ctext = [];
for i = 1:1:length(btext)
ctext = [ctext;strsplit(btext(i),' ')];
end
index = [index;length(btext)];
number_of_curves = length(index)-1;
Max_length_of_curve = max( index(2:1:length(index))- index(1:1:length(index)-1));
dtext = [];
for j = 1:1:number_of_curves
#CC = zeros(Max_length_of_curve-(index(j+1)-index(j)),2);
temp = [ctext(index(j):index(j+1)-1,:);repmat(ctext(index(j+1)-1,:),Max_length_of_curve-(index(j+1)-index(j)),1)];
dtext = [dtext,temp];
end
writematrix(dtext,'UHFwater-1-正斜入射(1).xls');%写入excel表格