필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Index exceeds matrix dimensions

조회 수: 2 (최근 30일)
Maryal
Maryal 2017년 12월 2일
마감: MATLAB Answer Bot 2021년 8월 20일
I have written this code but keep getting the error "Index exceeds matrix dimensions"
x=5
N = 30
i = 1 : N;
k = 5-i+(N-3);
y = 2 .* k(1:N-2) .* x(i(1:N-2)+1) + 3 .* x(i(1:N-2)-1);

답변 (1개)

Walter Roberson
Walter Roberson 2017년 12월 2일
Your original equation
y=2k*x(i+1)+3*x(i-1)
implies that x is a vector being indexed at i+1 and i-1.
Your current code has
x = 5;
which is a scalar. You cannot index a scalar at anything other than [] or 1 or true or false.
If your original code was intended to represent multiplication rather than indexing then:
y = 2 .* k(1:N-2) .* x .* (i(1:N-2)+1) + 3 .* x .* (i(1:N-2)-1);

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by