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

18 次查看(过去 30 天)
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

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2021-1-5
编辑:Fangjun Jiang 2021-1-5
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 个评论
Matteo Paiano
Matteo Paiano 2021-9-16
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,:) = []

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by