In an assignment A(I) = B, the number of elements in B and I must be the same? While Loop
Mostrar comentarios más antiguos
Hello! I am connecting an arduino sensor to Matlab to store the data being read from a sensor. The sensor has a proximity sensor attatched to it so that the sensor only reads data when something is in front of it. My problem is when I try to read all the values generated from the loop it gives me the error when nothing is in front of the sensor( nothing is being read): In an assignment A(I) = B, the number of elements in B and I must be the same.
However when I do not try to save every value, the code works fine when something is and is not in front of the sensor.
Code that does not store every iteration value generated in loop but works when something is and is not in front of data:
%e
s = serial('COM3');
set(s,'BaudRate',9600);
fopen(s);
out=[];
while 1
value = fscanf(s);
out(length(out) + 1) = str2num(value);
disp(out);
end
fclose(s)
Code that stores every iteration when something placed in front of sensor but gives me above error if nothing is in front of sensor:
s = serial('COM3');
set(s,'BaudRate',9600);
fopen(s);
out=[];
for i=1:60
value = fscanf(s);
out(length(out) + 1) = str2num(value);
disp(out);
end
fclose(s);
^ I've also tried doing while 1 instead of for i=1:60 but it still does not work
Please help I really do appreciate it! Thank you!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre MATLAB Support Package for Arduino Hardware en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!