Clear Filters
Clear Filters

for loop in equation

2 views (last 30 days)
Kutru biladi
Kutru biladi on 22 Jul 2015
Answered: Star Strider on 22 Jul 2015
Yo Volks, i am new in programming. i want to apply for loop in the equation 'phi_acc' which goes from '1 to nsamples' and after that want to put it in the phi equation.
phi_sync = rand(1,nsamples);
phi_acc = rand(1,nsamples);
phi = phi_sync(nsamples) + Phi_acc(nsamples);

Accepted Answer

Star Strider
Star Strider on 22 Jul 2015
The code you posted will take the last values of ‘phi_sync’ and ‘phi_acc’ to calculate ‘phi’. (Also, MATLAB is case-sensitive, so ‘Phi_acc’ is a different variable from ‘phi_acc’, and will throw an error if you haven’t defined it.)
If you want to add the two vectors of the same size, just use:
phi = phi_sync + phi_acc;

More 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!