MATLAB练习例子十四(模拟计算2)
返回
》 test30.m
??? Attempt to reference field of non-structure.
ソリューション:
ご使用のコンピュータ自体のネットワーク設定で "localhost" の名前解決ができていない場合にこのような現象になります。まず、使用中のコンピュータ自体の名前解決の確認を行うために MATLAB 上で以下のコマンドを実行します。
java.net.InetAddress.getLocalHost
または、コンピュータ自体に "ping" を送信し、応答があるかを確認します。
エラーとなる場合は、 /etc/hosts にホスト名を追加するなどの方法で名前解決します。
Don't put the .m after the test30.
It's thinking that you have a structure called test30 and that you're
trying to display the value of the "m" member of that structure in the
command window. Simply type m3 and hit enter.
--------------------------------------------------------------------
% fft001.m
fid = fopen('fftinput001.csv','r');
header1 = fgetl(fid);
%header1
header2 = fgetl(fid);
%header2
header3 = fgetl(fid);
%header3
header4 = fgetl(fid);
%header4
header = fgetl(fid);
header
D1 = fread(fid);
fclose(fid);
whos D1
---------------------------------------------
》 fft001
header =
TIME,ch1,ch2,,
Name Size Bytes Class
D1 326337x1 2610696 double array
Grand total is 326337 elements using 2610696 bytes
%fft2.m
t = 0:1/100:10-1/100;
x = sin(2*pi*50*t);
y = fft(x);
m = abs(y);
p = unwrap(angle(y));
f = (0:length(y)-1)'*100/length(y);
subplot(2,1,1), plot(f,m),
ylabel('Abs. Magnitude'), grid on
subplot(2,1,2), plot(f,p*180/pi)
ylabel('Phase [Degrees]'), grid on
xlabel('Frequency [Hertz]')
f=45Hz
f=50Hz
傅立叶变换
%fft1.m
t = 0:1/100:10-1/100;
x = sin(2*pi*15*t) + sin(2*pi*40*t);
y = fft(x);
m = abs(y);
p = unwrap(angle(y));
f = (0:length(y)-1)'*100/length(y);
subplot(2,1,1), plot(f,m),
ylabel('Abs. Magnitude'), grid on
subplot(2,1,2), plot(f,p*180/pi)
ylabel('Phase [Degrees]'), grid on
xlabel('Frequency [Hertz]')
龙格库塔法
% sim2_2.m
A = [0 1; -1 -1];
B = [0;1];
u = 1;
dt = 0.05;
tf = 20;
x = [0 0]';
xx = [];
i = 0;
for t = 0:dt:tf
i = i + 1;
xx(:,i) = x;
xt = x;
for j=1:4
f = A*x + B*u;
d(:,j) = f*dt;
x = xt + d(:,j)*0.5;
if j==3
x = xt + d(:,j);
end
end
x = xt + (d(:,1) + d(:,2)*2 + d(:,3)*2 + d(:,4))/6;
end
t = 0:dt:tf;
figure(1)
plot(t,xx)
grid on
欧拉法
% sim2_1.m
A = [0 1; -1 -1];
B = [0;1];
u = 1;
dt = 0.05;
tf = 20;
x = [0;0];
xx = [];
i = 0;
for t = 0:dt:tf
i = i + 1;
xx(:,i) = x;
dx = A*x + B*u;
x = x + dx*dt;
end
t = 0:dt:tf;
plot(t,xx)
grid on
返回