for loop in matlab

4 ビュー (過去 30 日間)
ali hassan
ali hassan 2020 年 11 月 18 日
編集済み: Cris LaPierre 2020 年 11 月 18 日
HELLO everyone
plz dont refer me to any link.i have a code for for loop.kindly explain it line by line if possibe.
BEST REGARDED.
CODE:
m = 1;
for n = 1:length(sol.xs)
possibleSol(1,m) = double(sol.xs(n));
possibleSol(2,m) = double(sol.ys(n));
possibleSol(3,m) = double(sol.zs(n))
m=m+1;
end
output:
  2 件のコメント
Cris LaPierre
Cris LaPierre 2020 年 11 月 18 日
What is it you don't understand?
  • How a for loop works
  • How to assign results to specific array elements using indexing
  • How to extract a value from a variable using indexing
  • what the function double is doing?
If you understand each of those, you can figure out what the loop is doing on your own.
ali hassan
ali hassan 2020 年 11 月 18 日
thanks for your kind reply.
i know double is changing precision and for loop will work for certain things. but i cant understand how output is changing.plzz explain

サインインしてコメントする。

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 11 月 18 日
編集済み: Cris LaPierre 2020 年 11 月 18 日
The values are changing because the indexing inside the for loop is telling it where to place the values.
I'm going to direct you to an interactive tutorial so you can learn and get some practice with the concept. See Ch 5 of MATLAB Onramp. If you need a little more explanation and practice with for loops, check out Ch 13.3 as well.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by