Use for loop in array

回答(1 个)

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

6 个评论

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

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Matrices 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