Getting error Index exceesds the numbers of array elements. Index must not exceeds 4 getting this error when calling the function in Runfile. Secondly needs help to modified

2 ビュー (過去 30 日間)
Getting error Index exceesds the numbers of array elements. Index must not exceeds 4 getting this error when calling the function in Runfile. Secondly needs help to modified this app in where we give different values of RLC in one edit field and also the time interval innone edit field.

回答 (1 件)

Romain
Romain 2024 年 8 月 5 日
Hello,
For your first problem:
RLC is a 1 by 4 vector and so to access its elements you use RLC(i) with i in [1,4].
In your if conditions line 137:
if RLC(j-1) < RLC(j) && RLC(j) < RLC(j+1)
When j = 1 you compare RLC(j=1) with RLC(j-1=0) (left side of the &&), the latter does not exist as the index must be in [1,4], you avoided it with your if at line 132:
if j == 1
Kb = Kb_Min;
end
Now you need to do the same thing when j = 4, otherwise you will compare RLC(j=4) with RLC(j+1=5) (right side of the &&). Use elseif for that.
I didn't check the whole file, but you will have to do the same thing for all other conditions where you make comparison using index such as i+n or i-n (as you did line 97 for instance with RLC(j-1) and RLC(j+1)): you must ensure that i+n and i-n are superior or equal to 1 and inferior or equal to vector length (same applies to matrix, arrays ...) .
I can't help you on your second problem as I'm on matlab R2022b and app was coded in R2023.
  2 件のコメント
Ehtisham
Ehtisham 2024 年 8 月 5 日
How i can make it more uniform so i did not get this error even i have large numbers of values like 10, 20 values for the RLC @Romain
Romain
Romain 2024 年 8 月 5 日
Let's say you have a for loop such as:
for jj = 1:upper_boundary
if jj == 1
% Code for index 1
elseif jj == upper_boundary
% Code for upper boundary, 4 when it comes to RLC in your case
else
% Code for in-between, using indexes such as jj+1 and jj-1
end
end
For the upper boundary, just replace upper_boundary in my example with the one you defined in your for loops.
That's one way to do it, you'd have more efficiency (resource wise) by narrowing the for range to 2:upper_boundary-1 and modifying the code according to it, but it's not really useful here due to the low complexity.

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

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by