combine double array question

조회 수: 2 (최근 30일)
m j
m j 2019년 6월 6일
댓글: Bob Thompson 2019년 6월 6일
Hello,
Im trying to get data from a COM port from a arduino and conveting it to a double.The goal is collect 1023 samples and store them in a array like, 5X1023, or 27X1023,12X1023,etc..... And ive tried y = [D y]; and y = [D; y];.....heres the simple code:and ive been using assignin only to show results and wont be used in final code. Please dont cruicify me.
Edit: so if a value passes a threshold get the next X samples and store them ....
s = serial('COM9');
assignin('base','s',s);
fopen(s);
j = 1;
i = 1;
thesh = 0;
countDown = 0;
strUp = 1;
d = [];
D= [];
n=1;
x = [];
y = [];
%begin contuious loop,in loop check each value,if a value passes
%a threshold,get next X samples!
%turn on loop upon startup
while(strUp == 1)
%check data from COM port of arduino
x = fscanf(s);
celldata(j) = cellstr(x);
d= str2double(celldata);
disp(celldata(j));
assignin('base','x',x);
assignin('base','d',d);
assignin('base','j',j);
pause(0.01);
%if value passed threshold,store next X samples
if(thesh == 1)
while(countDown >= 1)
x = fscanf(s);
celldata(j) = cellstr(x);
D= str2double(celldata);
j = j + 1;
disp(j);
assignin('base','j',j);
assignin('base','celldata',celldata);
pause(0.01);
countDown = countDown - 1;
if(countDown == 1) && (j == 1024)
assignin('base','y',y);
y = [D; y];
assignin('base','x',x);
assignin('base','D',D);
thesh = 0;
countDown = 0;
j=1;
d= 1;
end
end
end
%if data exceeds a threshold trigger recording
if (d > 1500 || d < 1000) && (thesh == 0)
%if triggered turn on bool that controls storage of wanted values
j = 1;
thesh = 1;
countDown = 1024;
end
end
  댓글 수: 6
m j
m j 2019년 6월 6일
examples :
a = zeros(1,8);
b = zeros(1,8);
c = [a; b];
equals = c 2 X 8
Bob Thompson
Bob Thompson 2019년 6월 6일
If you don't care about the number of rows, then why not just index with a colon as the row index. This will select all rows, no matter what size your array is. You can specify the column size separately to only include values you want.
C = A(:,1:1024);
If this isn't what you are looking for then I am obviously confused. Can you be more specific with reference to your code. Which variables are you hoping to make a certain size (I did not see 'a' anywhere in your code as a variable. str2double was used to create D, but I'm not sure what you're trying to do with it.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by