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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Romain
am 5 Aug. 2024
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 Kommentare
Romain
am 5 Aug. 2024
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.
Siehe auch
Kategorien
Mehr zu Number Theory finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!