Invalid expression...Line 16 column 48

function [x ,t,DR, DT]=homogeneous(N,dt,x0,R,T,eta,V,W)
kB=1.38e-23;
gamma=6*pi*R*eta;
DT=kB*T/gamma;
DR=6*DT/(8*R^2); x(1,:)=x0;
theta=0;
for n=1:1:N
x(n+1,:)=x(n,:)+sqrt(2*DT*dt)*randn(1,2);
theta=theta+sqrt(2*DR*dt)*randn(1,1);
theta=theta+dt*W;
x(n+1,:)=x(n+1,:) + dt*V*[cos(theta) sin(theta)];
cla
hold on
plot(x(1:n+1,1)) * 1e6;x(1:n+1,2)*1e6; 'k')
plot(x(n+1,1))*1e6;x(n+1,2)*1e6; 'o';...
'MarkerEdgeColor' ; 'k'; ...
'MarkerEdgeColor' ;'g')
hold off
axis equal square
title(['velocity= ' num2str(V*1e6) '\mum/s,' , ...
'angular velocity= ' num2str(W) 'rad/s,' , ...
'time= ', num2str(dt*(n+1)) 's'])
xlabel('x[\mum]')
ylabel('y[\mum]')
box on
axis equal
drawnow();
end
t=[0:dt:(N-1)*dt];

 Respuesta aceptada

Rik
Rik el 21 de Jul. de 2019
Editada: Rik el 21 de Jul. de 2019
You have a closing parenthesis too early:
plot(x(n+1,1))*1e6;x(n+1,2)*1e6
% ^
Also, you should use commas to separate arguments instead of semicolons.
Additionally, it does not make sense to use cla inside the loop. If you want to show only 1 plot, you should update the XData property instead of clearing the axes. You should also move the calls to title etc to outside the loop.

7 comentarios

Rik
Rik el 21 de Jul. de 2019
I think you may benefit from a crash course on using Matlab. None of what you wrote in that comment will work as intended.
If you have a 'not enough input arguments' error, you either need to provide the input arguments, or provide default values (use the nargin function, or use the exist function to determine if an input was provided).
Is this possibly intended for use in simscape ?
Notice that the line
W= +|- 3.14 rad 1/s .
is the only one where you use = and the only one where you do not use []
ilke
ilke el 21 de Jul. de 2019
function [x ,t,DR, DT]= Usfntitled(N,dt,x0,R,T,eta,V,W)
kB=1.38e-23;
gamma=6*pi*R*eta;
DT=kB*T/gamma;
DR=6*DT/(8*R^2);
x(1,:)=x0;
theta=0;
for n=1:1:N
x(n+1,:)=x(n,:)+sqrt(2*DT*dt)*randn(1,2);
theta=theta+sqrt(2*DR*dt)*randn(1,1);
theta=theta+dt*W;
x(n+1,:)=x(n+1,:) + dt*V*[cos(theta) sin(theta)];
cla
hold on
plot(x(1:n+1,1)*1e6,x(1:n+1,2)*1e6, 'k')
plot(x(n+1,1)*1e6,x(n+1,2)*1e6, 'o',...
'MarkerEdgeColor' , 'k', ...
'MarkerEdgeColor', 'g')
hold off
axis equal square
title(['velocity= ' num2str(V*1e6) '\mum/s,' , ...
'angular velocity= ' num2str(W) 'rad/s,' , ...
'time= ', num2str(dt*(n+1)) 's'])
xlabel('x[\mum]')
ylabel('y[\mum]')
box on
axis equal
drawnow();
end
t=0:dt:(N-1)*dt;
ilke
ilke el 21 de Jul. de 2019
"Additionally, it does not make sense to use cla inside the loop. If you want to show only 1 plot, you should update the XData property instead of clearing the axes. You should also move the calls to title etc to outside the loop" I couldn't do this one.But ,this code must be true but ı dont see any plot. I was hoping you might be able to help me with.
Rik
Rik el 21 de Jul. de 2019
Have you tried using the debugger to go through your code step by step? I don't have access to Matlab right now and you did not mention plausible inputs, so I can't test your code.
function [x ,t,DR, DT]= Usfntitled(N,dt,x0,R,T,eta,V,W)
kB=1.38e-23;
gamma=6*pi*R*eta;
DT=kB*T/gamma;
DR=6*DT/(8*R^2);
x(1,:)=x0;
theta=0;
ax = gca;
cla(ax);
for n=1:1:N
x(n+1,:)=x(n,:)+sqrt(2*DT*dt)*randn(1,2);
theta=theta+sqrt(2*DR*dt)*randn(1,1);
theta=theta+dt*W;
x(n+1,:)=x(n+1,:) + dt*V*[cos(theta) sin(theta)];
if n == 1
hold(ax, 'on')
h1 = plot(x(1:n+1,1)*1e6,x(1:n+1,2)*1e6, 'k');
h2 = plot(x(n+1,1)*1e6,x(n+1,2)*1e6, 'o',...
'MarkerEdgeColor' , 'k', ...
'MarkerEdgeColor', 'g')
hold(ax, 'off')
xlabel(ax, 'x[\mum]')
ylabel(ax, 'y[\mum]')
box(ax, 'on')
else
set(h1, 'XData', x(1:n+1,1)*1e6, 'YData', x(1:n+1,2)*1e6);
set(h2, 'XData', x(n+1,1)*1e6, 'YData', x(n+1,2)*1e6);
end
title(ax, ['velocity= ' num2str(V*1e6) '\mum/s,' , ...
'angular velocity= ' num2str(W) 'rad/s,' , ...
'time= ', num2str(dt*(n+1)) 's'])
axis(ax,'equal','square')
drawnow();
end
t=0:dt:(N-1)*dt;
ilke
ilke el 21 de Jul. de 2019
Thank you,I appreciated for your help.I will try to apply your suggestions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Jul. de 2019

Comentada:

el 21 de Jul. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by