how do i create an array from a for loop
Show older comments
i need to create 2 new arrays but it says there is a problem with maxdb in line 12

11 Comments
KSSV
on 11 May 2021
Copy paste the code here.......image snippet will not help us to help you.
Katherine Carcatsis
on 11 May 2021
Edited: KSSV
on 11 May 2021
KSSV
on 11 May 2021
Fist you have to define the variables theta, c. You have not defined them. Give thos values first.
Katherine Carcatsis
on 11 May 2021
KSSV
on 11 May 2021
This line
maxdb = max(db)
Should be:
[maxdb,index] = max(db)
But the code looks illogical.......what exactly you are trying the loop?
Jan
on 11 May 2021
"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
on 11 May 2021
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
on 11 May 2021
Jan
on 11 May 2021
@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
on 11 May 2021
Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!