冲击实验报告数据处理
- matlab - Home Page
要做一些冲击试验的位移荷载曲线图,写出如下 MATLAB 语言实现:
% Copyright © 2017 ZHANG <[email protected]>
% Distributed under terms of the MIT license.
clc; clear all
%% save_path: 图片要保存的目录
%% xlsxPath: .xlsx 文件存放目录
%% .m 文件放在 cwd 目录下
cwd = pwd;
save_path = strcat(cwd, '\pic\');
cd(save_path);
delete('*.emf');
xlsxPath = strcat(cwd, '\expreport\');
file_name = dir(xlsxPath);
fid = fopen('date.txt', 'w');
for i = 3:size(file_name)
filename = strcat(xlsxPath, file_name(i).name);
picName = file_name(i).name;
picName = picName(1:(find(picName=='.')-1));
[number, txt, raw] = xlsread(filename);
[m, n] = size(number);
if n == 4
xi = number(:,3);
yi = number(:,1);
date_time = number(:, 4);
elseif n == 3
xi = number(:,3);
yi = number(:,2) * 1000;
xi(1:10) = 0;
yi(1:10) = 0;
date_time = number(:, 1);
else
break
end
[maxL, indexL] = max(yi);
x = xi(indexL) * 0.7;
y = maxL * 0.98;
maxS = strcat(num2str(maxL/1000),'KN');
formatSpec = 'The time of %s is: %g.\n';
maxT = date_time(indexL);
str = sprintf(formatSpec, picName, maxT);
fprintf(fid, str)
figure
%% figure('visible','off')
plot(xi,yi,'k')
xlabel('Displacement(mm)', 'FontName', 'Time New Roman')
ylabel('Load(N)', 'FontName', 'Time New Roman')
ax = gca;
ax.YAxis.Exponent = 0;
text(x, y, maxS, 'FontName', 'Time New Roman', 'FontSize',10)
pic_name = [picName,'.emf']
saveas(gcf,pic_name)
close(gcf)
end
fclose(fid);