question of for loop

2 Ansichten (letzte 30 Tage)
mahesh chathuranga
mahesh chathuranga am 7 Sep. 2013
for i=1:10 power=(i*i) end; this is my programme and ,now i want to calculate all the values of power.
  1 Kommentar
mahesh chathuranga
mahesh chathuranga am 10 Sep. 2013
thak you very much.i'm very new for MATLAB

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 7 Sep. 2013
Do you have a question, other than "How do I format my code?" which is answered by this. Might it be "How do I get power to be an array?" If so, just make * a .* and drop the "for" and "end".
k = 1 : 10; % No "for" needed since it's now vectorized.
power = k .* k % or can use power = k .^2

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by