unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
2 ビュー (過去 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
0 件のコメント
回答 (1 件)
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'));
0 件のコメント
参考
カテゴリ
Help Center および File 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!