How to display graphically

조회 수: 1 (최근 30일)
lech king
lech king 2020년 11월 22일
댓글: Nora Khaled 2020년 11월 23일
Hello
I want the conditions of an issue to be graphically displayed at each step of the program. For example, in the case of a River crossing puzzle, I want to show which people (variables) are on which side of the river at each step.
Thanks
  댓글 수: 2
KSSV
KSSV 2020년 11월 22일
What data you have? You can display that using plot with some markers color depending on people are on which side.
lech king
lech king 2020년 11월 22일
In this case we have eight people
I considered each side an 1*8 representation
We move people according to the input received from the user
For example, if the first 2 people go from left to right, the situation will be left
001111111
The position will be on the right
11000000
How can I graphically show this situation now?

댓글을 달려면 로그인하십시오.

채택된 답변

Nora Khaled
Nora Khaled 2020년 11월 22일
편집: Nora Khaled 2020년 11월 22일
not sure this is what you had in mind ...
%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=[0 0 1 1 1 1 1];
right= [1 1 0 0 0 0 0 0];
% 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
scatter(pL(:,1),pL(:,2),'filled','SizeData',200)
alpha(.5)
scatter(pR(:,1),pR(:,2),'filled','SizeData',200)
alpha(.5)
the output looks like this
  댓글 수: 9
lech king
lech king 2020년 11월 23일
That's it
Thank you very much for your kindness
Nora Khaled
Nora Khaled 2020년 11월 23일
Sorry, I just realized... this just control the shape of the plot but does not mean that if a circle person moved from the left to the right that person will remain a circle.
If you want to assosiated the shape with the person... try this
shapes=['o' '+' 's' 'd' '.' '>' 'x' '*' '^'];
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
hope it helps.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by