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 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