Search this site
Embedded Files
Skip to main content
Skip to navigation
S&S 2018
首頁
Midterm
Final
S&S 2018
首頁
Midterm
Final
More
首頁
Midterm
Final
S&S
→Matlab - Paper, Scissors, Stone.
參考資料
→Introduction:
Using the orientations of the mobile phone to control what kind signal Matlab access.
At the same time, load in the simulink & stateflow to do logic control input signal trans to the logic control signal.
Paper, Scissors, Stone.
To win the world.
→My Code.
z = 1;
while z == 1
close all;
clear all;
clc; %clear front state
z = 0;
pig=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\Game.jpg');
image(pig); %show rule
set(figure(1),'NumberTitle','off','Name','Game') ; %set title
pause(2);
m = mobiledev;
pig=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\Start.png');
image(pig);
m.logging = 1;
pause(1.5); %connect 2 sec
m.logging = 0;
x = unidrnd(3); %random num(1.2.3)
coutput = x;
[or,tor] = orientlog(m); %set array
zAxis = or(:,3);
zAxis = zAxis(end);%load array data
load_system('FP_StateFlow');
sim('FP_StateFlow'); %run simulink and return
moutput = moutput(end);
if moutput == 1
pit=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\0.jpg');
elseif moutput == 2
pit=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\2.jpg');
elseif moutput == 3
pit=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\5.jpg');
else
pig=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\Error.png');
subplot(1,2,[1,2]),subimage(pig), title('Error') ;
pause(0.5);
end %your ans
if coutput == 1
pic=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\0.jpg');
elseif coutput == 2
pic=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\2.jpg');
elseif coutput == 3
pic=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\5.jpg');
else
disp('Error Way');
end %computer select
if and(coutput < 4, moutput < 4)
subplot(1,2,1),subimage(pic), title('Computer select') ;
subplot(1,2,2),subimage(pit), title('You select') ;
pause(1.5); %output result
k = coutput / moutput
if (k == 2 || k ==1.5 || k ==1/3)
pig=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\Win.png');
subplot(1,2,[1,2]),subimage(pig), title('Win') ;
else
pig=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\No Win.png');
subplot(1,2,[1,2]),subimage(pig), title('Win') ;
end %show resource
end
pause(1);
pig=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\Again.png');
subplot(1,2,[1,2]),subimage(pig), title('Again?') ;
pause(0.5);
pig=imread('C:\Users\Johnson\Documents\MATLAB\PAPER\YesNo.png');
subplot(1,2,[1,2]),subimage(pig), title('YesNo?') ;
m.logging = 1;
pause(2);
m.logging = 0;
[or,tor] = orientlog(m);
zAxis = or(:,3);
zAxis = zAxis(end); %next round?
if (zAxis < -120 || zAxis > 120)
z = 1;
else
close all;
end
end
→Demo
Final_Project.m
FP_StateFlow.slx
YesNo.png
Win.png
Start.png
No Win.png
Game.jpg
Error.png
Again.png
5.jpg
2.jpg
0.jpg
Google Sites
Report abuse
Google Sites
Report abuse