试图在MATLAB中创建一个子图,这个代码有意义吗



我正试图在matlab中创建一个子图,但这段代码似乎不可用。你对如何让它发挥作用有什么建议吗?我是一个编码新手,所以如果有任何帮助或建议可以在哪里搜索这样的东西,以防它不应该出现在这里,我将不胜感激。

Uinput=inputdlg({'width:',...
'thickness:',...
'length:',...
'density:',...
'natural frequency 1:',...
'natural frequency 2:',...
'natural frequency 3:',...
'natural frequency 4:',...
'damping ratio:'},...
'input',1,{'','','','','','','','',''});
w=eval(Uinput{1});
t=eval(Uinput{2});
L=eval(Uinput{3});
rho=eval(Uinput{4});
f1=eval(Uinput{5});
f2=eval(Uinput{6});
f3=eval(Uinput{7});
f4=eval(Uinput{8});
zn=eval(Uinput{9});
mnum=eval(Uinput{6});
%%
%COMMENT FROM HERE TO END
fn=[2.3481 14.7152 41.2033 80.7406]; % natural frequencies taken from task 1
kn=((2*pi.*fn).^2)*(L*w*t*rho); % equation to calculate the 
zn1=0.01;
zn=[zn1 zn1 zn1 zn1];
phif=[0.011 0.063 0.159 0.294]; %force potential amplitudes and the applied position %mode shapes for the forcing location   %nodes and antinode locations  %YOU NEED TO CHANGE THESE. mode shapes for the forcing location for each mode
%50mm, 302mm, 600mm 
phir=[0.3464 0.7112 -0.0083 -0.7455]; % response potential %modeshapes for the response locations     %YOU NEED TO CHANGE THESE. mode shapes for the response location for each mode
f=linspace(0,100,5000);
for n = 1:length(fn),
r = f/fn(n);
hi(:,n) = phif(n)*phir(n)/kn(n)./(1-r.^2+j*2*zn(n)*r);
phin=hi(:,n)/(max(abs(hi(:,n)));
subplot(2,2,n);
plot(x,phin, '-o')
grid on
xlabel('position')
ylabel('normalised shape')
title(['Mode ' num2str(mnum) ', ' num2str(fn) ' Hz'])
end
h=abs(sum(hi,2)); 
loglog(f,h)
ylabel('H')
xlabel('frequency (Hz)')

第34行缺少一个括号。第36行;x〃;在任何地方都没有定义。

在解决了这两个错误之后,该代码运行并绘制得很好。

#请尝试修改后的代码 #第34行-缺少括号 #第36行-请使用"x"变量,然后使用"f"变量绘制#plot(f,phin,'-o'(

Uinput=inputdlg({'width:',...
'thickness:',...
'length:',...
'density:',...
'natural frequency 1:',...
'natural frequency 2:',...
'natural frequency 3:',...
'natural frequency 4:',...
'damping ratio:'},...
'input',1,{'','','','','','','','',''});
w=eval(Uinput{1});
t=eval(Uinput{2});
L=eval(Uinput{3});
rho=eval(Uinput{4});
f1=eval(Uinput{5});
f2=eval(Uinput{6});
f3=eval(Uinput{7});
f4=eval(Uinput{8});
zn=eval(Uinput{9});
mnum=eval(Uinput{6});
%%
%COMMENT FROM HERE TO END
fn=[2.3481 14.7152 41.2033 80.7406]; % natural frequencies taken from task 1
kn=((2*pi.*fn).^2)*(L*w*t*rho); % equation to calculate the 
zn1=0.01;
zn=[zn1 zn1 zn1 zn1];
phif=[0.011 0.063 0.159 0.294]; %force potential amplitudes and the applied position %mode shapes for the forcing location   %nodes and antinode locations  %YOU NEED TO CHANGE THESE. mode shapes for the forcing location for each mode
%50mm, 302mm, 600mm 
phir=[0.3464 0.7112 -0.0083 -0.7455]; % response potential %modeshapes for the response locations     %YOU NEED TO CHANGE THESE. mode shapes for the response location for each mode
f=linspace(0,100,5000);
for n = 1:length(fn)
r = f/fn(n);
hi(:,n) = phif(n)*phir(n)/kn(n)./(1-r.^2+ j*2*zn(n)*r);
phin=hi(:,n)/(max(abs(hi(:,n))))
subplot(2,2,n);
plot(f,phin, '-o')
grid on
xlabel('position')
ylabel('normalised shape')
title(['Mode ' num2str(mnum) ', ' num2str(fn) ' Hz'])
end
h=abs(sum(hi,2)); 
loglog(f,h)
ylabel('H')
xlabel('frequency (Hz)')

相关内容

  • 没有找到相关文章

最新更新