Trying to create a text file with 3000 rows of data and 7 columns.

1 回表示 (過去 30 日間)
N/A
N/A 2019 年 3 月 7 日
編集済み: N/A 2019 年 3 月 7 日
I want to create a text file with 7 columns titled Time, Ax, Ay, Az, p, q ,r.
Each column should possess 3000 rows of randomnly generated data from the range of 0:2
I have the following code.
Time = -2 + (2+2)*rand(3000,1);
Ax = 0 + (2+2)*rand(3000,1);
Ay = -1 + (2+2)*rand(3000,1);
Az = -2 + (2+2)*rand(3000,1);
p(angular rate along x) = -2 + (2+2)*rand(3000,1);
q(angular rate along y) = -2 + (2+2)*rand(3000,1);
r(angular rate along z) = -2 + (2+2)*rand(3000,1);
T = table(Time, Ax, Ay, Az, p, q ,r);
writetable(T, 'SampleIMUDATA.txt');
type SampleIMUDATA.txt
Im trying to create this text file in such a way where these numbers are randomnly generated everytime when I run the script, and overwrite the previous contents of the file SampleIMUDATA.txt
When I run the script I get the following error:
>> SampleIMUDATA
Error: File: SampleIMUDATA.m Line: 5 Column: 15
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
syntax error. To construct matrices, use brackets instead of parentheses.
I initally thought the dimensions of the 1 by 3000 matrix I was generating were wrong but that doesn't seem wrong so I'm wondering where the error is in dimensions.
Thanks

採用された回答

Geoff Hayes
Geoff Hayes 2019 年 3 月 7 日
Shivam - what is your intent with this code
p(angular rate along x) = -2 + (2+2)*rand(3000,1);
q(angular rate along y) = -2 + (2+2)*rand(3000,1);
r(angular rate along z) = -2 + (2+2)*rand(3000,1);
Is the above where the error is being generated? I don't understand the use of "angular rate along x". Is this supposed to be a title or something else?
If I remove this text and run just
Time = -2 + (2+2)*rand(3000,1);
Ax = 0 + (2+2)*rand(3000,1);
Ay = -1 + (2+2)*rand(3000,1);
Az = -2 + (2+2)*rand(3000,1);
p = -2 + (2+2)*rand(3000,1);
q = -2 + (2+2)*rand(3000,1);
r = -2 + (2+2)*rand(3000,1);
T = table(Time, Ax, Ay, Az, p, q ,r);
writetable(T, 'SampleIMUDATA.txt');
then the file is created with seemingly the correct format.
  1 件のコメント
N/A
N/A 2019 年 3 月 7 日
編集済み: N/A 2019 年 3 月 7 日
I spent 3 hours working on different codes so I missed that blatant mistake. I was initially trying to comment that p q and r represented angular rates coming in from a gyroscope from x y and z for my knowledge.
This is embarrasing...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by