主题:求助:调用TXT文件出错,请高手帮我解决一下,非常感谢!!!
我用Matlab编了一个程序,想把下面txt文件(文件名:30u)中的数据调用出来,进行傅立叶逆变换!!!
文件30u的内容如下:
% Coordinates
0.2 3.3737995E-9
0.2375 -1.6647773E-9
0.275 -2.8869866E-9
0.3125 6.6000445E-9
0.35 1.08717595E-8
0.3875 3.7726917E-8
0.425 1.082493E-8
0.4625 -2.9036307E-9
0.5 -5.787301E-10
0.5375 9.643958E-10
0.575 1.5052295E-9
0.6125 -2.0961077E-9
0.65 7.007234E-9
0.6875 1.7817277E-7
0.725 6.990347E-8
0.7625 -1.7719842E-8
0.8 -6.562405E-8
编的程序如下:
clear
clc
format long e
N=2000;
n=0:N-1;
fp=fopen('30u.txt', 'r');
t=fscanf(fp, '%d %d');
fclose('all');
for i=1:16
a(i) = t(i*2-1);
b(i) = t(i*2);
end
f=a(i)
c=n/2*pi*N
X=b(i)
Y=ifft(X,N)
subplot(2,1,1)
plot(f,X)
subplot(2,1,2)
plot(c,Y)
Matlab程序提示我出错:
??? Index exceeds matrix dimensions.
Error in ==> E:\MtLab\Untitled1.m
On line 10 ==> a(i) = t(i*2-1);
请大家帮帮忙啊!!!!万分感谢!!!
文件30u的内容如下:
% Coordinates
0.2 3.3737995E-9
0.2375 -1.6647773E-9
0.275 -2.8869866E-9
0.3125 6.6000445E-9
0.35 1.08717595E-8
0.3875 3.7726917E-8
0.425 1.082493E-8
0.4625 -2.9036307E-9
0.5 -5.787301E-10
0.5375 9.643958E-10
0.575 1.5052295E-9
0.6125 -2.0961077E-9
0.65 7.007234E-9
0.6875 1.7817277E-7
0.725 6.990347E-8
0.7625 -1.7719842E-8
0.8 -6.562405E-8
编的程序如下:
clear
clc
format long e
N=2000;
n=0:N-1;
fp=fopen('30u.txt', 'r');
t=fscanf(fp, '%d %d');
fclose('all');
for i=1:16
a(i) = t(i*2-1);
b(i) = t(i*2);
end
f=a(i)
c=n/2*pi*N
X=b(i)
Y=ifft(X,N)
subplot(2,1,1)
plot(f,X)
subplot(2,1,2)
plot(c,Y)
Matlab程序提示我出错:
??? Index exceeds matrix dimensions.
Error in ==> E:\MtLab\Untitled1.m
On line 10 ==> a(i) = t(i*2-1);
请大家帮帮忙啊!!!!万分感谢!!!