combine double array question

2 次查看(过去 30 天)
m j
m j 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 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by