how do i create an array from a for loop
古いコメントを表示
i need to create 2 new arrays but it says there is a problem with maxdb in line 12

11 件のコメント
KSSV
2021 年 5 月 11 日
Copy paste the code here.......image snippet will not help us to help you.
Katherine Carcatsis
2021 年 5 月 11 日
編集済み: KSSV
2021 年 5 月 11 日
KSSV
2021 年 5 月 11 日
Fist you have to define the variables theta, c. You have not defined them. Give thos values first.
Katherine Carcatsis
2021 年 5 月 11 日
KSSV
2021 年 5 月 11 日
This line
maxdb = max(db)
Should be:
[maxdb,index] = max(db)
But the code looks illogical.......what exactly you are trying the loop?
Jan
2021 年 5 月 11 日
"it says there is a problem" - then please post a complete copy of the error message. It can contain important details.
"with maxdb in line 12" - show us, which is the "line 12". If the users count, they have to guess, that you did not crop initial blank lines or comments.
The purpose of the code is not clear:
- "db;" This line displays the contents of db, while surpressing the output. So nothing happens.
- The body of the loop does not depened on the loop counter "a".
- "index" is undefined.
- "c = 30-a;" c is not used anywhere.
- maxdb is overwritten twice in each iteration.
- "theta" is undefined.
Katherine Carcatsis
2021 年 5 月 11 日
What is theta?
I guess:
sint = sin(theta.');
db = -a .* sint - (a.^2 * cos(theta.') .* sint) ./ ...
sqrt(c.^2 - a.^2 * sint .^ 2);
Katherine Carcatsis
2021 年 5 月 11 日
Jan
2021 年 5 月 11 日
@Katherine Carcatsis: The statement "theta is just an angle" is not meaningful. How should Matlab calculate the value of db, if you use a variable, which is "just an angle"?
The purpose of the loop is still unclear, but now it is getting clear, that you do know, what the first line should do.
Which problem should the code solve? What are the inputs and what do you want to calculate?
Katherine Carcatsis
2021 年 5 月 11 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!