6 views (last 30 days)
Show older comments
lech king on 22 Nov 2020
-
-
Link
Direct link to this question
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically
Commented: Nora Khaled on 23 Nov 2020
Accepted Answer: Nora Khaled
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 Comments Show NoneHide None
Show NoneHide None
KSSV on 22 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1152208
What data you have? You can display that using plot with some markers color depending on people are on which side.
lech king on 22 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1152288
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?
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Nora Khaled on 22 Nov 2020
Edited: Nora Khaled on 22 Nov 2020
Open in MATLAB Online
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 Comments Show 7 older commentsHide 7 older comments
Show 7 older commentsHide 7 older comments
lech king on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1153658
Thank you Thank you
This is exactly it
Thank you very much
lech king on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1153673
Is it possible for each point to have a specific color ??
Nora Khaled on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1153728
Open in MATLAB Online
you could plot them in a loop like
for i=1:1:nL
scatter(pL(i,1),pL(i,2),'filled','SizeData',200)
alpha(.5)
end
for i=1:1:nR
scatter(pR(i,1),pR(i,2),'filled','SizeData',200)
alpha(.5)
end
in this case you will not need the alpha(.5) to change the transparency.
lech king on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1153743
Thank you very much
Nora Khaled on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1153768
you're welcome
lech king on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1154158
Edited: lech king on 23 Nov 2020
Thank you for your help
In this case, each point indicates an independent person. Is it possible that each person has a unique shape ??
For example, the first person is a triangle and the second person is a square and .......
Nora Khaled on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1154173
Open in MATLAB Online
Yes
shapes=['o' '+' 's' 'd' '.' '>' 'x' '*' '^'];
for i=1:1:nL
scatter(pL(i,1),pL(i,2),shapes(i),'SizeData',200)
alpha(.5)
end
for i=1:1:nR
scatter(pR(i,1),pR(i,2),shapes(i+nL),'SizeData',200)
alpha(.5)
end
However, in this case you can not use the property filled.
you can see all shapes avalible here:
https://www.mathworks.com/help/matlab/ref/scatter.html
lech king on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1154188
That's it
Thank you very much for your kindness
Nora Khaled on 23 Nov 2020
Direct link to this comment
https://matlabcentral.mathworks.com/matlabcentral/answers/656938-how-to-display-graphically#comment_1154198
Open in MATLAB Online
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.
Sign in to comment.
More Answers (0)
Sign in to answer this question.
See Also
Categories
MATLABGraphicsFormatting and Annotation3-D Scene ControlLighting, Transparency, and Shading
Find more on Lighting, Transparency, and Shading 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!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office