How to store real time loop data in MATLAB?

1 次查看(过去 30 天)
I have the problem with the real time loop data. I can't store it because it only stores the last number that created with for loop. The code is seen below
clear all;
close all;
clc;
s = serial('COM8','BaudRate',9600);
set(s,'DataBits',8);
set(s,'StopBits',1);
s.ReadAsyncMode='continuous';
readasync=(s);
y1=cell(1,100);
y1_1=cell(1,100);
y1_2=zeros(100,1);
y2=0;
y3=0;
y5=0;
y_est=zeros(100,1);
v_est=0;
x=0;
i=0;
j=1;
fopen(s);
for x=1:100
y=fscanf(s);
d=length(y);
if d==8
l=y(1); m=y(7);
if l=='B' && m=='E'
y1 = mat2cell(y, ones(size(y,1),1), size(y,2));
y1 = strrep(y1, 'B', '');
y1_1= strrep(y1, 'E', '');
y1_2 = cellfun(@str2num, y1_1)
end
end
%Encoder milimeter
y1{x}=magic(x);
y1_1{x}=magic(x);
y1_2(x,1)=x*(1);
y2 = y1_2/360;
figure(1);
subplot(2,1,1);plot(x,y2,'*');
title('Encoder Milimeter');
xlabel('x-axis');ylabel('y-axis');
hold on;
%grid on;
end
How I can store the real-time looping data?
Thank you,
Setiawan
Note: I'm using ALtera for data acqusition.
  2 个评论
KSSV
KSSV 2017-3-1
编辑:KSSV 2017-3-1
What is s? Which variable you want to save?
Setiawan Putra Hendratno
编辑:Setiawan Putra Hendratno 2017-3-1
s=serial('COM8','BaudRate',9600);
I want to save the encoder's value (y2) in milimeter. But, It has only one last data to save.

请先登录,再进行评论。

回答(1 个)

KSSV
KSSV 2017-3-1
s = serial('COM8','BaudRate',9600);
set(s,'DataBits',8);
set(s,'StopBits',1);
s.ReadAsyncMode='continuous';
readasync=(s);
y1=cell(1,100);
y1_1=cell(1,100);
y1_2=zeros(100,1);
y2=0;
y3=0;
y5=0;
y_est=zeros(100,1);
v_est=0;
x=0;
i=0;
j=1;
fopen(s);
iwant = cell(100,1) ;
for x=1:100
y=fscanf(s);
d=length(y);
if d==8
l=y(1); m=y(7);
if l=='B' && m=='E'
y1 = mat2cell(y, ones(size(y,1),1), size(y,2));
y1 = strrep(y1, 'B', '');
y1_1= strrep(y1, 'E', '');
y1_2 = cellfun(@str2num, y1_1)
end
end
%Encoder milimeter
y1{x}=magic(x);
y1_1{x}=magic(x);
y1_2(x,1)=x*(1);
y2 = y1_2/360;
iwant{x} = y2 ;
figure(1);
subplot(2,1,1);plot(x,y2,'*');
title('Encoder Milimeter');
xlabel('x-axis');ylabel('y-axis');
hold on;
%grid on;
end
iwant is a cell. You can access it using iwant{1},iwant{2}...
  3 个评论
KSSV
KSSV 2017-3-1
I think your y2 is a array. So I am not sure of it's length, so better put them into a cell.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by