What I'm looking to do is create a script that will put the values between 1 and 50 by increments of 0.5 in a Matrix after they go through the equation 331+(0.6*k). This is what I have so far but it only gives me one value and I'm stumped on how to do a matrix with all of the values:
for k=0:0.5:50;
wave=331+(0.6*k);
end

 Accepted Answer

You would have to set up a separate index variable to do that in a for loop:
k = 0:0.5:50;
for kk = 1:numel(k)
wave(kk) = 331+(0.6*k(kk));
end
However MATLAB can do that calculation in one line, without the explicit loop:
k = 0:0.5:50;
wave = 331+(0.6*k);

2 Comments

Thank you!
As always, my pleasure!
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!