Error Unable to delete elements from this array because dimension 1 has fixed size 1000
10 views (last 30 days)
Show older comments
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
Answers (1)
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);
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
Matteo Paiano
on 16 Sep 2021
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,:) = []
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!