Monday 15 April 2013

Scilab: How to find first 1 in each column without loops -


I'm trying to find the first 1 in each column of the matrix without using it for a while or without. Say I have

  - & gt; AA = 0. 0. 0. 0. 0. 1. 1. 1. 0. 1. 1. 1. 1. 0. 0.   

Then I would like to get [1,4,2,2] (I can assume that there is always 1 in each column). This thing happens when I use Search (A), it gives me [1,3,4,8,10,11,14,15] .

I was not told to use Loops but because the matrix operation Cylab handles better to the last ones.

Thank you in advance!

With such a small matrix display, for loops and probably enough to be readable May be enough. But one solution to avoid using the loop can be in the form of the following. Find all the rows and colors of people in

  // a [row, cola] = a (a); // Find a new column index desp (find all row positions in the search (search ([1, diff (col)]));   

I think the more readable solution would be like the following:

  // col column = 1: 4 for each column only the first event disp (Search (A (Colonel), 1)); In the end,   

As stated, such a small matrix should have a high priority with readability. You can measure the performance of both (or other) solutions

If you want to read more about some performance enhancement techniques, take a look.

No comments:

Post a Comment