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

조회 수: 7 (최근 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
  댓글 수: 2
Naufal Arfani
Naufal Arfani 2021년 1월 6일
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

댓글을 달려면 로그인하십시오.

답변 (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에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by