开发者

Retaining handle matrix size upon deletion

开发者 https://www.devze.com 2023-03-26 22:27 出处:网络
I have created a set of lines in a figure. The line handles occupy a matrix created by imline.empty(0,x). When I delete a certain line (using delete(.)), the matrix changes in size. I want to avoid th

I have created a set of lines in a figure. The line handles occupy a matrix created by imline.empty(0,x). When I delete a certain line (using delete(.)), the matrix changes in size. I want to avoid this by filling that particular place in the matrix with empty space (or anything else) in order to keep the data structured, and the matrix the same size. 开发者_开发问答What is the best way to do this?


Building on my previous answer, consider this example:

lines = imline.empty(0,10);
for i=1:10
    lines(i) = imline(gca, rand(2,2));
end

Now say we want to delete the third and last lines:

Before

>> whos lines
  Name       Size            Bytes  Class     Attributes

  lines      1x10               96  imline   

>> lines.isvalid
ans =
     1     1     1     1     1     1     1     1     1     1

After

>> delete( lines([3 end]) )

>> whos lines
  Name       Size            Bytes  Class     Attributes

  lines      1x10               88  imline     

>> lines.isvalid
ans =
     1     1     0     1     1     1     1     1     1     0

So the array stay the same size when delete-ing...

If you want to actually remove their entries from the array, try:

>> lines(~lines.isvalid) = [];
>> size(lines)
ans =
     1     8
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号