Effacer les filtres
Effacer les filtres

unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

2 vues (au cours des 30 derniers jours)
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

Réponses (1)

Guillaume
Guillaume le 25 Fév 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'));

Catégories

En savoir plus sur MATLAB Support Package for Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by