How to Split numbers into matrix

Hi guys, im currently working on EMG recording trough Arduino and EMG Shield. the problem is that i have to record the signal from two muscles, since that, i have to read two values from to arduino and save into a Matlab variable the kind of values that comes from arduino are two numbers like 514;125 so, how can i read those values and save them into a matrix with two columns?? this is my code from recording so far.
if true
% code
end
delete(instrfind({'Port'},{'COM3'}));
port=serial('COM3');
port.BaudRate=115200; %
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(port);
Fs=1/5000;
t=0;
i=1;
tic;
tmax=2;
while t<tmax;
if toc >(Fs)
valor=fscanf(port,'%d') %here i read the output from arduino
raw(i)=valor(1,1);
t=t+toc;
tic;
end
fclose(port);
delete(port);
thx

 采纳的回答

You should update the index i inside your while, if loop. Also you now only store the first value of valor.
raw = zeros(1000,2) ; % pre-allocation of a buffer for speed
i = 0 ;
...
while t < tmax
valor = ...
i = i + 1 ; % put it in the next row
raw(i,1:numel(valor)) = valor ; % will work if valor has less or more than 2 elements
...
end
raw = raw(1:i,:) ; % truncate unfilled rows

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Instrument Control Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by