How to store real time loop data in MATLAB?

4 vues (au cours des 30 derniers jours)
Setiawan Putra Hendratno
Setiawan Putra Hendratno le 1 Mar 2017
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 commentaires
KSSV
KSSV le 1 Mar 2017
Modifié(e) : KSSV le 1 Mar 2017
What is s? Which variable you want to save?
Setiawan Putra Hendratno
Setiawan Putra Hendratno le 1 Mar 2017
Modifié(e) : Setiawan Putra Hendratno le 1 Mar 2017
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.

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 1 Mar 2017
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 commentaires
KSSV
KSSV le 1 Mar 2017
I think your y2 is a array. So I am not sure of it's length, so better put them into a cell.
Setiawan Putra Hendratno
Setiawan Putra Hendratno le 1 Mar 2017
Okay, thanks for your sharing code.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by