Azzera filtri
Azzera filtri

Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0.

1 visualizzazione (ultimi 30 giorni)
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
A = zeros(64,1);
B = zeros(64,1);
C = zeros(64,1);
D = zeros(64,1);
Arduino=serial('COM3','BaudRate',9600);%!!!!!!!!need to change the port for windows!!!!!!
fopen(Arduino);
writedata=uint16(500); %0x01F4
fwrite(Arduino,writedata,'uint16') %write datac
for s = 1:1
for i=1:64 %read 64 lines of data
%A(i,1) = fscanf(Arduino,'%f')
A(i,1) = fscanf(Arduino,'%f');
end
B = A;
D(1,1) = abs(B(3,1)-B(4,1));
D(2,1) = abs(B(4,1)-B(5,1));
D(3,1) = abs(B(5,1)-B(6,1));
D(4,1) = abs(B(6,1)-B(7,1));
D(5,1) = abs(B(7,1)-B(8,1));
D(6,1) = abs(B(12,1)-B(13,1));
D(7,1) = abs(B(13,1)-B(14,1));
D(8,1) = abs(B(14,1)-B(15,1));
D(9,1) = abs(B(15,1)-B(16,1));
D(10,1) = abs(B(16,1)-B(9,1));
D(11,1) = abs(B(17,1)-B(18,1));
D(12,1) = abs(B(21,1)-B(22,1));
D(13,1) = abs(B(22,1)-B(23,1));
D(14,1) = abs(B(23,1)-B(24,1));
D(15,1) = abs(B(24,1)-B(17,1));
D(16,1) = abs(B(25,1)-B(26,1));
D(17,1) = abs(B(26,1)-B(27,1));
D(18,1) = abs(B(30,1)-B(31,1));
D(19,1) = abs(B(31,1)-B(32,1));
D(20,1) = abs(B(32,1)-B(25,1));
D(21,1) = abs(B(33,1)-B(34,1));
D(22,1) = abs(B(34,1)-B(35,1));
D(23,1) = abs(B(35,1)-B(36,1));
D(24,1) = abs(B(39,1)-B(40,1));
D(25,1) = abs(B(40,1)-B(33,1));
D(26,1) = abs(B(41,1)-B(42,1));
D(27,1) = abs(B(42,1)-B(43,1));
D(28,1) = abs(B(43,1)-B(44,1));
D(29,1) = abs(B(44,1)-B(45,1));
D(30,1) = abs(B(48,1)-B(41,1));
D(31,1) = abs(B(49,1)-B(50,1));
D(32,1) = abs(B(50,1)-B(51,1));
D(33,1) = abs(B(51,1)-B(52,1));
D(34,1) = abs(B(52,1)-B(53,1));
D(35,1) = abs(B(53,1)-B(54,1));
D(36,1) = abs(B(58,1)-B(59,1));
D(37,1) = abs(B(59,1)-B(60,1));
D(38,1) = abs(B(60,1)-B(61,1));
D(39,1) = abs(B(61,1)-B(62,1));
D(40,1) = abs(B(62,1)-B(63,1));
Hom(:,s) = D;
end
Currently facing this error. We are trying to read 3V input from mux via Arduino .Please help.
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0.

Risposte (1)

VBBV
VBBV il 9 Feb 2023
Modificato: VBBV il 9 Feb 2023
for i=1:64 %read 64 lines of data
%A(i,1) = fscanf(Arduino,'%f')
%A(i,1) = fscanf(Arduino,'%f');
A(i,1) = read(Arduino,64,"uint16")
end
As you are trying to read data from serial port device, Matlab recommends to use read function instead of fscanf to read data. fscanf seems a better option to read data from files. The matrix B seems to be empty since nothing has been read. It also appears, that serial function is not recommended by Matlab.
  1 Commento
Walter Roberson
Walter Roberson il 9 Feb 2023
you would only use read() if you switch to serialport()
In this kind of situation you would readline() and sscanf() or potentially str2double(). read() is binary read like fread() not like fscanf

Accedi per commentare.

Categorie

Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by