MATLAB Answers

Error Unable to delete elements from this array because dimension 1 has fixed size 1000

79 views (last 30 days)
Naufal Arfani
Naufal Arfani on 5 Jan 2021
Commented: Naufal Arfani on 10 Jan 2021
hello everyone, I want to delete the first row from the 2D Matrix array [11x1000] because it is all 0 so it interferes and causes the process to not continue. But when you want to delete it with the two codes below, maybe because the element is deleted it results in a reduced value in the matrix so it can't [10x1000], I've asked this before and someone said that it can be with variable copy but I don't understand how. when I tried the code below on the workspace it could but when I tried it on the simulink an error appeared as in the title, can anyone tell me a good way to solve the error, I'm an amateur in Matlab and Simulink so really need your help, thank you


Naufal Arfani
Naufal Arfani on 6 Jan 2021
I'm sorry @Matt Gaidica, the explanation is exactly what has been said below, so I have a problem with the fixed size in the matlab function block in simulink like @Fangjun Jiang said

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 5 Jan 2021
Edited: Fangjun Jiang on 5 Jan 2021
You kept asking similar questions on this topic. You need to ask your question precisely and accurately. The key point for this question is that you need to mention that the error happened in "MATLAB Function" block in Simulink.
In MATLAB, removing one row is very simple.
>> A=rand(5,8);
ans =
4 8
The first row has been removed.
In the "MATLAB Function" block in Simulink, because most variables (especially inputs and outputs) have fixed size (dimension), removing rows or columns like above will cause the error message in your title.
To avoid this, click "Edit Data" in the MATLAB Function block editor, select the variable on the left, on the right, specify the maximum size (for example, [11 1000]), check "Variable size". By this way, you have defined the varialbe as variable size data. Then you can remove rows or columns like above and change the size of the variable. But keep in mind, variable size data in Simulink is quite tricky. You might have other errors down the line.


Show 2 older comments
Fangjun Jiang
Fangjun Jiang on 9 Jan 2021
put a breakpoint in the code and debug it. The problem is quite obvious.
Right at the begining of the simulation, the value of input "u" is all 1 (same as ones(501,1)). So both "pks" and "locs" returned by "[pks,locs] = findpeaks(u)" are empty. You can't run "a = locs(2)-locs(1)".
The code is not robust anyway. You always need to check whether there is a peak or not and then decide the next step.
The error can be dupicated the same way as below in MATLAB.
[pks,locs] = findpeaks(u);
a = locs(2)-locs(1)
Naufal Arfani
Naufal Arfani on 10 Jan 2021
I'm sorry, I can only see it now,
I'm sorry I'm still a bit amateur in Matlab and Simulink, do you mean I just need to add this code or what else do you need to do?
please help me by explaining the step by step, please help me a little more Mr @Fangjun Jiang.
I don't understand related to put a breakpoint in the code and debug it, please help me.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!