Use for loop in array

How to use the for loop in array with a start value of 0?

回答 (1 件)

KSSV
KSSV 2019 年 6 月 10 日

0 投票

a = rand(10,1) ;
for i = 1:length(a)
a(i)
end

6 件のコメント

hang dong
hang dong 2019 年 6 月 10 日
Can I start with 0?
KSSV
KSSV 2019 年 6 月 10 日
No..MATLAB does not accept index as zero. It should be positive integer.
hang dong
hang dong 2019 年 6 月 10 日
So is there a way for me to replace 0?
KSSV
KSSV 2019 年 6 月 10 日
What is your purpose? Explain your problem.
hang dong
hang dong 2019 年 6 月 10 日
I want to create an array of n elements, then programmatically to swap values ​​in that S array, in the array containing element 0
KSSV
KSSV 2019 年 6 月 10 日
You can get the index of 0 using
idx = find(a==0)

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

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

質問済み:

2019 年 6 月 10 日

コメント済み:

2019 年 6 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by