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 Comments

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

Sign in to comment.

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Products

Release

R2018b

Asked:

on 12 Feb 2020

Answered:

on 30 Dec 2020

Community Treasure Hunt

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

Start Hunting!