How to store real time loop data in MATLAB?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
KSSV
on 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 Comments
KSSV
on 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.
See Also
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!