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

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

2 Comments

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)

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);
A(1,:)=[];
size(A)
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.

7 Comments

forgive me if you always pay attention to me always asking on the same topic because indeed I am currently working on my final project in college, and yes I seem to forget to emphasize that this is the matlab function block on simulink, for your advice @Fangjun Jiang thank you because I have trying that thing is looking for edit data and writing like your example and checking the variable size but there is still an error like that is there any next step I need to do? thank you very much once again I'm sorry if you keep asking repeatedly
Make a simple example to show the problem so others can duplicate the problem to help you.
here is my simulink if you want to check it by yourself @Fangjun Jiang
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.
u=ones(501,1);
[pks,locs] = findpeaks(u);
a = locs(2)-locs(1)
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.
I've read your clear answer. I also have the same question, I don't know if I should write another post.
I use a "variable size" list but not as input nor output, so I can't actually "Edit Data".
I'll copy some code as an example, for debug porpouse I just want the list to be displayed in the Diagnostic Viewer. The function simply append variables to the list, sort it according to the variable "cost" (4th column) and (would like to) remove the first row.
function fcn
X = [20 20 20]; cost = 10; action = 20; LA = 20;
l = [X,cost,action,LA];
X = [0 0 0]; cost = 0; action = 0; LA = 0;
l = [l; X,cost,action,LA]
[id,id] = sort(l(:,4));
l = l(id,:)
l(1,:) = []

Sign in to comment.

Products

Asked:

on 5 Jan 2021

Commented:

on 16 Sep 2021

Community Treasure Hunt

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

Start Hunting!