How to store real time loop data in MATLAB?
2 ビュー (過去 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 件のコメント
回答 (1 件)
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
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 Center および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!