Error message when running code: "Dimension argument must be a positive integer scalar"
50 次查看(过去 30 天)
显示 更早的评论
I have this error message and i don't know what to do please help?
Error using size
Dimension argument must be a positive integer scalar or a vector of positive integers.
Error in practice (line 36)
x=zeros(size(n,q));
The code:
clear;
m1=3000;k=13650;
mass=[m1,0,0;0,4*m1,0;0,0,m1];
M=input('mass');
[n,o]=size(M);
if n~=o
error('mass');
end
stiff=[k+k,-k,0;-k,k+k,-k;0,-k,k+k];
K=input('stiff');
[n,o]=size(K);
if n~=o
error('stiff');
end
qu=0;
[u,l]=eig(K,M);
% Using eigin this way allows us to subtract M*w^2
% from K, instead of I*w^2 (where I is the n by n identity
% matrix).
% The output from eiggives unit-length eigenvectors.
% We need to scale them with respect to M.
%
for s=1:n
alfa=sqrt(u(:,s)'*M*u(:,s));
u(:,s)=u(:,s)/alfa;
end
inid=[0;0;0];
iniv=[0;0;0];
x0=input('inid');
xd0=input('iniv');
final=[];
tf=input('final');
t=0:0.1:tf;
q=tf/0.1;
x=zeros(size(n,q));
% Applying Equation 7.183.
%
for j=1:n
w(j)=sqrt(l(j,j));
xt=u(:,j)*(u(:,j)'*M*x0*cos(w(j).*t)+u(:,j)'*M*xd0/...
w(j)*sin(w(j).*t));
x=x+xt;
end
% Plotting the modes in a subplot format.
% Note that, for more than 3 or 4 degrees
% of freedom, the plots will become nearly
% unreadable.
%
for r=1:n
subplot(n,1,r)
plot(t,x(r,:))
xlabel('Time, seconds');
ylabel(['Response x',num2str(r)]);
end
0 个评论
回答(2 个)
Chandler Hall
2022-11-14
编辑:Chandler Hall
2022-11-14
x=zeros(size(n,q))
Perhaps you intend:
x = zeros(size(n, 1), numel(t));
2 个评论
Image Analyst
2022-11-15
What values did you enter? I entered 4, 5, 4, 4, and 4 and got no such error with the code above.
Are you sure you actually entered a number and didn't just hit Enter (to give a null value)?
Also, n and q need to be integers. So you might correct
q=tf/0.1;
x=zeros(size(n,q));
to this
q = 10 * tf;
x = zeros(size(n, q));
Why? See the FAQ:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!