MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by C Zeng
on 20 Jun 2013

Hi, it is a follow up of a previous question, but I have not successfully solved it.

Assume I have a large matrix(many rows), and try to remove as many rows as I want. The criterion of removing a row j is that if there is a row i in lower row# (i<j) and row i<=row j and then we call row i dominates row j rand remove row j(while keep row i).

To do a complete removal, I need to check to every row, check if any of its row above it can dominates it. When the size of matrix is very large (in my case) the program is very slow.

Now I think of a method that can avoid wasting time on dominated rows. Whenever I find 1000 rows that are dominated, I delete them from the matrix and continue the work. In such a way, the size of matrix can get smaller and smaller. However I am aware that changing the size of a variable also costs time. There is a tradeoff.

Last week Walter Roberson communicated with me about if there is opportunity of speedup if keeping the size of variable smaller. It seems that not very possible unless we need additional memory on hard drive. Otherwise if in the RAM, there might not be a difference on large of small size of your data.

If so, let me go back to my problem, changing the variable may not be good. How about keep a linked array that it only contains non-dominated rows but in reverse order and it likes "10->8->5->2->1" I would like to save it as a stack, i.e., Whenever I push a number number, it shows up in the first entry.

How to define and make a stack happen? Note I have to define the size, but I do not know it yet.

Thanks.

*No products are associated with this question.*

Answer by C Zeng
on 20 Jun 2013

Edited by C Zeng
on 20 Jun 2013

Accepted answer

This may be helpful:

http://www.mathworks.com/matlabcentral/fileexchange/28922-list-queue-stack

Jan Simon
on 5 Aug 2013

@C Zhend: You have accepted the answer, which means, that the problem is solved. Now you are asking for an advice?

## 3 Comments

## C Zeng (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/79695#comment_156016

Let me use professional word here: I said changing the size I meant preallocate the variable.

## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/79695#comment_162979

I do not understand the question completely. How large is your matrix? "Very large" could mean 2000 or 20'000'000 rows. "Very slow" can mean seconds or weeks. Do you want to improve the performance of your code? Then post it here. Operating on rows must be slower than on columns due to accessing neighboring elements of the memory.

I cannot follow at these points:

What is a "linked array" in your case or what does "saving as a stack" exactly mean?

## C Zeng (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/79695#comment_163149

Hi, Jan, it has been two months, and now I found a method to solve this problem. No need to be a stack. What I did is simply create another array to record the subset number and its order.

Thanks all the same.