how to solve error Index exceeds matrix dimensions. The array locs is empty and therefore has no valid indices.

hello everyone, I have an array of frequency domain fft on simulink of [11x501] and I want to enter into the matlab function block containing the findpeaks code but then the error appears above, what should I do if maybe I need to change the leading zeros to another number? But it can't be a constant or monotonous number, is it possible that someone should know how to duplicate another array to fill in the leading zero?
I have tried to delete it but then an error appeared, namely unable to delete element in this array because this array has fixed size.
is there someone who can provide help? thank you for your attention

Answers (1)

u(1,:) = -u(2,:)
unless the second row is 0.
If the second row is 0 then you need to scan down the column to determine whether there is any non-zero. If not then set the first row to 1 to force it to be a peak.
But really since you are looping the findpeaks just test to see whether the findpeaks is empty and if so arbitrarily designate one of the positions as a peak.

11 Comments

But then I realized that this is a time matrix so it will read from the first row, can it still be duplicated? @Walter Roberson
Those are not times, those are frequency domain fft results. It looks like they are single-sided and absolute value only.
Just take the second output of max() to get the bin number.
I'm sorry if I ask all of you too often, because I'm also confused about how to set a good example for all of you because I use simulink,
I will attach my file below maybe you can download it or you can tell me how I can give a good example so you can understand, thank you
I have tried your way @Walter Roberson but it still doesn't work
if there is anything I can do to make you understand please let me know @Walter Roberson
To get the model to work, I had to switch the sine source from continuous to discrete.
yes because that's the problem, the problem with my main simulink is that the induction motor input is in the form of continuous sin, that's why I'm very confused about the output buffer which causes the value 0 in the first row of the time matrix @Walter Roberson
The buffer is not causing output of 0. If you put a scope on the output of the DSP.sin then the output is already 0 if you are in continuous mode.
yes at first there was 0 so I also thought about removing 0 from the start, namely from the DSP output sin continuous mode,
I want to know if with 0 it is removed whether it will make my buffer not produce 0 in the first frame, if you know how? @Walter Roberson
The DSP Buffer block is defined to hold the previous content until enough new samples have been received to fill a complete frame, at which point the output changes to the appropriate number of previous values.
Between the time the buffer operation starts and the time a full frame of samples have been received, the "previous content" is typically 0. You can configure for a different initial value in the properties of the DSP Buffer block, which also permits you to name a variable to receive the initial values from.
... You would not be continuing to have this problem if you had followed my advice,
" just test to see whether the findpeaks is empty and if so arbitrarily designate one of the positions as a peak."
I'm sorry if I'm still an amateur in Matlab and Simulink, but can you give me more explanation about the two suggestions that you gave above? I seemed quite catchy but couldn't figure out how @Walter Roberson

Sign in to comment.

Products

Asked:

on 7 Jan 2021

Commented:

on 10 Jan 2021

Community Treasure Hunt

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

Start Hunting!