matlab 读取txt文本,并分析数据
close all; clc; clear; str = ‘E:\matlab\temp_data\‘; files = dir(strcat(str,‘*.txt‘)); number_files = length(files); x = zeros(number_files,4526); y = zeros(number_files,4526); N = 5; a = zeros(number_files,N+1); fun_name = blanks(number_files); for i=1:number_files str1 = sprintf(‘%s%s‘,str,files(i).name); [temp,lev] = textread(str1,‘%f,%f‘); x(i,:) = temp; y(i,:) = lev - lev(1); a(i,:) = polyfit(x(i,:),y(i,:),N) figure; plot(x(i,:),y(i,:)); freq = str2num(files(i).name(regexp(files(i).name,‘\d‘))); if (freq < 1e3) str2 = sprintf(‘%s%.1f%s‘,‘频率:‘,freq,‘Hz‘); elseif(freq <1e6) str2 = sprintf(‘%s%.4f%s‘,‘频率:‘,freq/1e3,‘kHz‘); elseif(freq < 1e9) str2 = sprintf(‘%s%.7f%s‘,‘频率:‘,freq/1e6,‘MHz‘); else str2 = sprintf(‘%s%.10f%s‘,‘频率:‘,freq/1e9,‘GHz‘); end title(str2); legend(‘温度-幅度‘); xlabel(‘温度‘); ylabel(‘幅度‘); end %%阶数判断 % for i=1:5 % y2=polyfit(x,y,i); % Y=polyval(y2,x);%计算拟合函数在x处的值。 % if sum((Y-y).^2)<0.1 % c=i % break; % end % end
读取文本函数:[temp,lev] = textread(str1,‘%f,%f‘);
扫描文件夹函数
str = ‘E:\matlab\temp_data\‘;
files = dir(strcat(str,‘*.txt‘));
相关推荐
wwwdownmacom 2020-09-14
wanff0 2020-07-26
cuiguanjun 2020-07-26
HongAndYi 2020-07-04
知识小屋 2020-06-24
wanff0 2020-06-14
cuiguanjun 2020-06-13
liqing 2020-06-13
algorithmlixuan 2020-06-12
faustcao 2020-06-12
GerwelsJI 2020-06-09
zyazky 2020-06-08
cuiguanjun 2020-06-05
Canethui 2020-05-31
Canethui 2020-05-30
zyazky 2020-05-29
zyazky 2020-05-19
zyazky 2020-05-17