필터 지우기
필터 지우기

Index exceeds the number of array elements (3).

조회 수: 1 (최근 30일)
Pimpawee Khumsup
Pimpawee Khumsup 2021년 9월 4일
댓글: Walter Roberson 2021년 9월 4일
n = input('What"s your ""favorite"" number? ')
twiceYourFavoritePlusOne = 2*n + 1
myFavorites = linspace(2,8,3)
yourFavorites = 2:3:6
myFavorites(yourFavorites)
yourFavorites(myFavorites) = 6
myFavoritesSquares = myFavorites.*myFavorites
if (rem(n,2) == 0)
disp('even')
else
disp('odd')
end
ages4review = [19 7 4 2; 14 89 62 50; 2 3 2 12]

답변 (1개)

Chunru
Chunru 2021년 9월 4일
What is the purpose of your code?
n = 4; %input('What"s your ""favorite"" number? ')
twiceYourFavoritePlusOne = 2*n + 1
twiceYourFavoritePlusOne = 9
myFavorites = linspace(2,8,3)
myFavorites = 1×3
2 5 8
yourFavorites = 2:3:6
yourFavorites = 1×2
2 5
myFavorites(yourFavorites)
Index exceeds the number of array elements (3).
% myFavorites has only 3 numbers. yourFavourites has index 2 and 5.
% The index 5 exceeds the number of elements in myFavorites.
yourFavorites(myFavorites) = 6
myFavoritesSquares = myFavorites.*myFavorites
if (rem(n,2) == 0)
disp('even')
else
disp('odd')
end
ages4review = [19 7 4 2; 14 89 62 50; 2 3 2 12]
  댓글 수: 5
Pimpawee Khumsup
Pimpawee Khumsup 2021년 9월 4일
There are invalid dots in the code. Use a debug mode and have to modify the code to be correct.
Walter Roberson
Walter Roberson 2021년 9월 4일
The only dots I see in the code are in
myFavoritesSquares = myFavorites.*myFavorites
but that is not invalid.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by