combine double array question

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
Bob Thompson 2019 年 6 月 6 日
What exactly is your question for us? What are you looking for help with?
m j
m j 2019 年 6 月 6 日
Great question. So how do i store data in a manner like "a" X 1024 were "a" can be 1,5,12,134,1546,`32444,etc.....Ive stated and tried storing my data from coverting str2double and then tried to store the data as stated above, eg..."a" X 1024.
Bob Thompson
Bob Thompson 2019 年 6 月 6 日
How are you determining the size of 'a'? I understand that it can be variable, but what conditions specify that variability?
m j
m j 2019 年 6 月 6 日
編集済み: m j 2019 年 6 月 6 日
I dont care about size of "a", size of a can be whatever it wants to be,within the while loop. Once threshold is passed get next X samples. "a" X 1024 ,only thing that matters is the 1024 data samples I collect. Edit:specify the variability? I dont understand this sorry.
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 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

m j
2019 年 6 月 6 日

コメント済み:

2019 年 6 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by