# MATLAB: How to read multiple sensors through the serial.

arduinoMATLABserial

Hi guys
I hope you can help me.
I have connected 4 force sensors to an Arduino, and I´m sending the data to the serial port simultanious – no problems so far.
Now I would like Matlab to read the serial and plot 4 graphs, 1 from each sensor.
The data in the serial are organized in 8 coloums with a description and the value for each sensor.
My problem is, that I dont know how to seperate the serial so each of the four dataset is placed in its own variable so I afterwards can make the plots.
This is my code:
clear allclcarduino=serial('COM4','BaudRate',9600);fopen(arduino);x=linspace(1,100);for i=1:length(x);y(i)=fscanf(arduino,'%f'); endfclose(arduino)
This very basic code only reads the first "coloum" in the serial – how do I add the other coloum, so I can get that data as well?
I appreciate any help 🙂
Best regards Kasper

numcols = 8;y = zeros(length(x), numcols);for k = 1 : numcols  for i=1:length(x);    y(i, k)=fscanf(arduino,'%f');   endendplot(y);
numcols = 8;y = zeros(length(x), numcols);fmt = repmat('%f', 1, numcols);for i=1:length(x);  y(i, :) = fscanf(arduino, fmt); endplot(y);