unable to establish serial connection between arduino ide and matlab

hi,i want the motor to rotate initially,then i have calculated the focus image index value in matlab,i want to send the value to arduino ide and the motor should rotate and come back to focus index value.
but its not happening

4 comentarios

%matlab code
clc;
clear all;
CAMERA = videoinput('pointgrey', '1');
start(CAMERA);
pause(1);
a = serial('COM3','BaudRate',9600);
fopen(a);
pause(1);
fprintf(a,'%i',index)
fclose(a)
for i = 1:20
filename = sprintf('testtry%02d.jpg',i);
img = im2double(getsnapshot(CAMERA));
img = rgb2gray(img);
stop(CAMERA)
imwrite(img,filename)
end
D = 'C:\Users\PRL\Desktop\just';
S = dir(fullfile(D,'*.jpg')); % pattern to match filenames.
for k = 1:numel(S)
F = fullfile(D,S(k).name);
a(k) = bodekke(F);
end
plot(a);
[m,index] = max(a)
hold on
plot(index,m,'*')
hold off
title("bodekke with spot images")
function[addition] = bodekke(imagename)
im = double(imread(imagename))
bd = [-1 0 1]
cbd = conv2(im,bd)
squaredcbd = cbd.^2
addition = sum(squaredcbd(:))
end
fprintf(a,'%i',index)
index is not a defined variable at that point.
yes sir,i also get the same error i calculate the index value in matlab after i close the serial port,so only i get the error.
i tried to move the fprintf and fclose() command after second loop where i finished calculating index value,for that i get a different error.
any ideas or help please?

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.

Productos

Versión

R2018b

Preguntada:

el 12 de Feb. de 2020

Respondida:

el 30 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by