MATLAB Answers

How to graphically represent man in MATLAB

3 views (last 30 days)
lech king
lech king on 29 Nov 2020
Hello
I implemented the river problem in MATLAB and used the following function to graphically represent this problem (which Nora Khaled was kind enough to draw for me).
As you can see, people are represented in the problem with these shapes
shapes=['+' '^' 'x' 's' '*' 'd' '|' '_'];
I wanted to ask if it is possible to present this issue in a better way and with better symbols ??
function[]=Enve(A,B)
%Environment
envSize=4;
figure;
x=-envSize:0.1:envSize;
y=.5*sin(x);
plot(y,x,'lineWidth',10)
axis([-envSize envSize -envSize envSize]);
hold on;
%Input
left=A;
right= B;
% number of ppl
nL=sum(left);
nR=sum(right);
%random position for ppl
maxX=envSize-1;
minX=2*max(y);
maxY=envSize-1;
minY=-(envSize-1);
pL = [-(minX + (maxX-minX) .* rand(nL,1)), (minY + (maxY-minY) .* rand(nL,1))];
pR = [(minX + (maxX-minX) .* rand(nR,1)) , (minY + (maxY-minY) .* rand(nR,1))];
% plot
shapes=['+' '^' 'x' 's' '*' 'd' '|' '_'];
leftcounter=1;
rightcounter=1;
for i=1:1:nL+nR
if left(i) ==1
scatter(pL(leftcounter,1),pL(leftcounter,2),shapes(i),'SizeData',200)
alpha(.5)
leftcounter=leftcounter+1;
else
scatter(pR(rightcounter,1),pR(rightcounter,2),shapes(i),'SizeData',200)
alpha(.5)
rightcounter=rightcounter+1;
end
end

  0 Comments

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!

Translated by