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

%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?

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

답변 (1개)

카테고리

도움말 센터File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2020년 2월 12일

답변:

2020년 12월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by