Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% FST SIMULATION, BY BRAD
- clear; clc; close all;
- % LETS MAKE A BUCKET
- [x,y,z] = cylinder(5);
- CYL.X = x;
- CYL.Y = y;
- CYL.Z = z .* 10;
- % AND A RAT
- [x,y,z] = sphere;
- RAT.X = x .* 2;
- RAT.Y = y .* 2;
- RAT.Z = z .* 3 + 7;
- % PUT THE RAT IN THE BUCKET
- figure('Units','normalized','OuterPosition',[.1 .05 .6 .8],'Color','w');
- axes('Position',[.1 .1 .8 .8],'Color','none');
- ph1 = surf(CYL.X,CYL.Y,CYL.Z);
- ph1.FaceAlpha = .4;
- axis equal; hold on
- surf(RAT.X,RAT.Y,RAT.Z)
- view([40 20])
- %% MOTION IN THE OCEAN
- clc; clearvars -except CYL RAT
- % CREATE MOTION BY SAMPLING FROM A RANDOM NORMAL DIST
- mu = 0;
- sd = 1;
- M = randn(1000,1) .* sd + mu;
- close all
- fh1 = figure('Units','normalized','OuterPosition',[.01 .06 .9 .9],'Color','w');
- ax1 = axes('Position',[.05 .55 .88 .43],'Color','none');
- ax2 = axes('Position',[.05 .05 .40 .43],'Color','none');
- ax3 = axes('Position',[.55 .05 .40 .43],'Color','none');
- % Plot simulated FST motion
- axes(ax1); plot(M);
- % Plot histogram
- axes(ax2); histogram(M);
- % Plot eCDF
- [F,x] = ecdf(M);
- axes(ax3); plot(x,F)
- xlabel('x'); ylabel('F(x)')
- %% A RAT IN A BUCKET, FORCED TO SWIM
- clc; %close all;
- clearvars -except CYL RAT M
- % PUT THE RAT IN THE BUCKET
- fh1 = figure('Units','normalized','OuterPosition',[.1 .05 .6 .8],'Color','w');
- ax1 = axes('Position',[.1 .1 .8 .8],'Color','none');
- ph1 = surf(CYL.X,CYL.Y,CYL.Z);
- ph1.FaceAlpha = .4;
- axis equal; hold on
- S = surf(RAT.X,RAT.Y,RAT.Z);
- view([40 20]); hold on;
- AX.X = ax1.XLim;
- AX.Y = ax1.YLim;
- AX.Z = ax1.ZLim;
- MO.X = M(randperm(length(M)));
- MO.Y = M(randperm(length(M)));
- MO.Z = M(randperm(length(M)));
- XD = RAT.X;
- YD = RAT.Y;
- ZD = RAT.Z;
- cx = cumsum(MO.X).*.1;
- cy = cumsum(MO.Y).*.1;
- cz = cumsum(MO.Z).*.1;
- for i = 1:100
- S.XData = XD+cx(i);
- S.YData = YD+cy(i);
- S.ZData = ZD+cz(i);
- ax1.XLim = AX.X;
- ax1.YLim = AX.Y;
- ax1.ZLim = AX.Z;
- view([40 20]);
- pause(.05)
- % BOUTS OF GIVING-UP
- if mod(i,20)==0
- for j = 1:80
- S.ZData = S.ZData - j*.0005;
- pause(.02)
- end
- for k = 1:40
- S.ZData = S.ZData + j*.0005;
- pause(.01)
- end
- end
- end
- disp('DONE')
Add Comment
Please, Sign In to add comment