将数据保存在矩阵中,并在matlab中单独绘制

时间:2015-07-08 14:09:35

标签: matlab

我从四个传感器的串行端口及其contionus数据中收集数据。 我尝试了这个逻辑,但是你可以检查代码

delete(instrfindall);
s= serial('/dev/tty.usbserial-A702LF1Z', 'BaudRate', 9600, 'DataBits',8,'Timeout',10)

 while(true)
  a1=str2num(fscanf(s,'%c',6)) %reads the data from the serial port and  stores it to the matrix a
   s1=a1(a1>10 & a1<19)
   s2=a1(a1>20 & a1<29);
   s3=a1(a1>30 & a1<39);
   s4=a1(a1>40 & a1<49);
   z=[z s1];
   plot(z,'Color','g');
   y=[y s2];
   plot(y,'Color','r');
   x=[x s3]


  I get values ranging from four sensors 
  FLUX1 :    FLUX2 :     FLUX3:   FLUX4:   
   10.00        20.00       30.00       40.00


   but i get max values form each senors is 

    15.00       25.00         35.00       45.00

我不需要考虑上面的19,29,39和49 我需要为每个传感器单独保存数据并将其单独绘制

1 个答案:

答案 0 :(得分:1)

我想这就是你想要的

a = 10:2:50;
ind = 0:3;
f = @(x) a(a>=(10+10*x) & a<=(20+10*x));
M = arrayfun(@(x) f(x), ind, 'UniformOutput',0);

>> celldisp(M)

M{1} =

    10    12    14    16    18    20



M{2} =

    20    22    24    26    28    30



M{3} =

    30    32    34    36    38    40



M{4} =

    40    42    44    46    48    50