Save data from Serial port of Arduino to a text file using MATLAB
Mostra commenti meno recenti
I read the data from a serial port to the MATLAB. I need to save the data to the text file using MATLAB. How to write the incoming data from the serial port to a text file instead of naming the first characters as data from the left sensor "left = [left, str2num(out(1:6))]" and 7: end as right sensors?
instrreset()
s = serial('/dev/cu.usbmodem66375701');
set(s,'BaudRate',9600);
Tmax=5;
tic;
left=[];
right=[];
fopen(s);
while toc<Tmax
out = fgetl(s);
fprintf('%s\n',out);
left = [left, str2num(out(1:6))];
right = [right, str2num(out(7:end))];
end
fclose(s);
fileName1=['savingthedata.txt'];
fid = fopen((fileName1),'wt');
if fid == -1
error('Cannot open file: %s', fileName1); AND HERE
end
fprintf(fid,'%6s %6s\n','Left sensor','Right sensor');
fprintf(fid,'%6.2f %6.8f\n',left,right);
fclose(fid);
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Text Files in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!