unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
1 view (last 30 days)
Show older comments
if ~isempty(instrfind)
fclose(instrfind)
end
arduino=serial('COM3','BaudRate',9600);
fopen(arduino);
i=1;
tic;
while (toc<=400)
%while 1
time(i) = toc;
s(i) = fscanf(arduino,'%c');
% subplot(3,1,1);plot(time,R,'linewidth'1.5);
% xlabel('t');ylabel('v');title('Reference');grid ON;
%
% subplot(3,1,2)
plot(time,s,'linewidth',1.5);
xlabel('time');ylabel('v');title('test');grid ON;
%
% sub[lo(3,1,3);plot(time,R,time,s,'linewidth',1.5);
% xlabel('t'):ylabel('v');title('Together');legend('Ref','Test');gride ON;
drawnow
i=i+1;
end
0 Comments
Answers (1)
Guillaume
on 25 Feb 2020
The documentation is not very clear, but I believe that fscanf(arduino, '%c') is the same as fscanf(arduino) and that this reads as many characters as are available, not just one. So, if you want to read just one character at a time, then:
s(i) = fscanf(arduino, '%c', 1); %read just one character
If you meant to read all characters then you can't store multiple characters as a single element i of a vector, so you'll have to read the text as element of a cell array or a string array:
s{i} = fscanf(arduino, '%c');
%or
s(i) = string(fscanf(arduino, '%c'));
0 Comments
See Also
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!