有關(guān)數(shù)據(jù)讀入matlab
hfss方法CST前些日子在論壇見不少人都對(duì)讀入數(shù)據(jù)有些迷茫
cst、hfss的數(shù)據(jù)基本格式是描述性語(yǔ)言+數(shù)據(jù)的格式
下面是一個(gè)cst的數(shù)據(jù)輸出
Frequency / GHz SZmin(1),Zmin(1)/abs,linear
-----------------------------------------------------------------
5 0.4557996
5.029 0.4553181
5.058 0.4547905
5.087 0.4542164
5.116 0.4535954
5.145 0.452927
5.174 0.4522107
5.203 0.4514461
但是matlab沒有這么高的領(lǐng)悟了,不會(huì)自己讀數(shù)據(jù)
方案不少說(shuō)一說(shuō)常用的。
1自己手動(dòng)刪除
Frequency / GHz SZmin(1),Zmin(1)/abs,linear
-----------------------------------------------------------------
然后使用
load (文件名).txt
不錯(cuò)的方法,如果你文件名是純數(shù)字的,比如是24,在matlab的workspace中會(huì)有一個(gè)X24的數(shù)組。
下面對(duì)x24處理就是了。
2一些人比較懶,不愿意刪東西
可以這樣:
[f,tr]=textread('24.txt','%f%f',2);
先到上面在看一下cst的數(shù)據(jù)結(jié)構(gòu),這里的2 是說(shuō)從第3行開始讀數(shù)。
如果你的數(shù)據(jù)是大于兩列的,有幾列,在[a1,a2,a3……]就是幾個(gè)向量,同時(shí),"%f%f……"中的%f的個(gè)數(shù)和前面的列向量的個(gè)數(shù)相同。
3有些時(shí)候儀器的輸出比較牛,我們的古董級(jí)別的失網(wǎng)的輸出是csv格式的帶編碼的數(shù)據(jù)。
# Version 1.00
#
freq[Hz];re:Trc1_b2d1sam[V];im:Trc1_b2d1sam[V];
1.700000000000000E+011;7.317389423714706E-003;-3.586198237922638E-003;
1.701500000000000E+011;-8.718488268764849E-003;5.495278251522440E-003;
1.703000000000000E+011;-1.050072140670953E-002;3.472822925688487E-003;
可以這么處理
fid=fopen('C:Documents and SettingsAdministratorMy Documents58.csv','r');% open file
i=0;
while 1 %get the length of the data
tline = fgetl(fid);
if ischar(tline), break, end
i=i+1;
end
fclose(fid); %the array can't go back, when it get the bottom of the file. so open the file again
fid=fopen('C:Documents and SettingsAdministratorMy Documents58.csv','r');
temp=fgetl(fid); % due to the structure of the data, first three line is useless.
temp=fgetl(fid);
temp=fgetl(fid);
for j=1:1:i-3 %read the data
temp=fgetl(fid);
a=strrep(temp,';',' '); % use the 'table' to replace ';'
[b,c]=strtok(a);
[e,f]=strtok(c);
data(j,1)=str2double(b);
data(j,2)=str2double(e);
data(j,3)=str2double(f);
end
4事實(shí)上,我們的數(shù)據(jù)量比較大,可以一次打開多個(gè)文件
clc
close all
clear all
t1=27;
t2=30;
for t=t1:1:t2
f=strcat(num2str(t),'.cvs');
g='C:Documents and SettingsAdministratorMy Documents4.13';
fid=fopen(strcat(g,f),'r+');
t1,t2可以自己指定。因?yàn)閷?shí)驗(yàn)數(shù)據(jù)是要測(cè)60次取均值的,導(dǎo)師一直是這么要求的。如果讓你刪60個(gè)文件的說(shuō)明的話,會(huì)發(fā)瘋的。
5上面的這些都是對(duì)不會(huì)使用dos的人寫的
如果你會(huì)使dos,十分簡(jiǎn)單,寫一個(gè)批處理文件,在matlab的m文件的一開始執(zhí)行一下
Frequency / GHz SZmin(1),Zmin(1)/abs,linear
-----------------------------------------------------------------
5 0.4557996
5.029 0.4553181
5.058 0.4547905
馬上全部變成
5 0.4557996
5.029 0.4553181
5.058 0.4547905
現(xiàn)在我們的實(shí)驗(yàn)室都是在用批處理的方式來(lái)寫的,因?yàn)閿?shù)據(jù)太多了。。。。
先寫到這里了,希望對(duì)大家數(shù)據(jù)處理有幫助。
不錯(cuò),多謝樓主奉獻(xiàn)
貌似用matlab直接處理不是那么簡(jiǎn)單,lz的第二個(gè)方法好像不行
可以的啊,在我的機(jī)器運(yùn)行的很正常。要不你把數(shù)據(jù)給我,我?guī)湍銓懸粋€(gè)m文件?
謝謝了!?。?!