global com;
arduino = serial(com,'BaudRate',9600);
try
fopen(arduino);
catch
instrreset;
fopen(arduino);
end
baca=fscanf(arduino, '%s');%1x7 14 char
fclose(arduino);
cell = strsplit(baca,'#');
sensor=cell2mat(cell(1,1));
val=cell2mat(cell(1,2));
set(handles.txt12,'String',sensor);
clear all
clc
serialPort=serial('COM4','BaudRate',9600);
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(serialPort);
volt=[10,10,10,101,10,10,10,10];
%Voltages are mapped from 0-10 to 0-100000
for i=1:length(volt)
voltmapped(i)=map2(volt(i),0,10,0,100000);
end
display('Press any button to continue.');
pause
for i=1:length(voltmapped)
fprintf(serialPort,'%d',voltmapped(i));
end
fclose(serialPort);
Selasa, 14 Februari 2017
Kamis, 09 Februari 2017
Referensi Montecarlo
link download :
https://www.youtube.com/watch?v=Xr4a6Dw6qcc
simple code:
% Monte Carlo computation of pi. n = input(' Enter n: '); count = 0; % Generate random points in the square [-1,1]X[-1,1]. % The fraction of these that lie in the unit disk % x^2+y^2 <= 1 will be approximately pi/4. % Think of this as taking the average of N independent % identically distributed random variables X_i, where % X_i = 1 if point i lies in the disk, 0 otherwise. Eofxsq = 0; % Compute expected value of X_i^2 to use in error estimate. for i=1:n, x = 2*rand-1; y = 2*rand-1; if x^2 + y^2 <= 1, count = count + 1; Eofxsq = Eofxsq + 1^2; end; end; pi_approx = 4*(count/n), err = pi - pi_approx, Eofxsq = Eofxsq/n; varx = Eofxsq - (count/n)^2; % Variance in individual approximations to pi/4. sigx = sqrt(varx); % Std dev in individual approximations to pi/4. sigma = 4*sigx/sqrt(n), % Std dev in total approximation to pi. fprintf('Error should be less than %f, 68.3 percent of the time\n',sigma) fprintf('Error should be less than %f, 95 percent of the time\n',2*sigma)Selamat Mencoba.....
Senin, 06 Februari 2017
Matlab Code SImple LVQ / SOM
function
scan(img)
files = dir(
'*.jpg'
);
hist = [];
for
n = 1 : length(files)
filename = files(n).name;
file = imread(filename);
hist = [hist, imhist(rgb2gray(imresize(file,[ 50 50])))];
%#ok
end
som = selforgmap([10 10]);
som = train(som, hist);
t = som(hist);
%extract class data
net = lvqnet(10);
net = train(net, hist, t);
like(img, hist, files, net)
end
====================
function
like(im, hist, files , net)
hs = imhist(rgb2gray(imresize(im,[50 50])));
cls = vec2ind(net(hs));
[~, n] = size(hist);
for
i = 1 : n
if
(cls == vec2ind(net(hist(:, i))))
figure(
'name'
, files(i).name);
imshow(imresize(imread(files(i).name), [100 100]))
end
end
end
Reff:
Langganan:
Postingan (Atom)