필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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

답변 (1개)

Guillaume
Guillaume 2020년 2월 25일
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'));

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by