Invalid expression...Line 16 column 48

1 view (last 30 days)
ilke
ilke on 21 Jul 2019
Commented: ilke on 21 Jul 2019
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];

Accepted Answer

Rik
Rik on 21 Jul 2019
Edited: Rik on 21 Jul 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 Comments
Walter Roberson
Walter Roberson on 21 Jul 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;
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 on 21 Jul 2019
Thank you,I appreciated for your help.I will try to apply your suggestions.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!