combine double array question
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
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 Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!