From: Jan on 11 Jan 2010 06:24 I've been programming in Matlab for quite a while now, but recently I ran into a problem that I can't solve in a neat and efficient way. I have a 2D matrix A (lets say 32x32) and a vector B (lets say its length is 16). Now I want to find 16 largest values in matrix A. Then I want to add first component of vector B to largest element in A, second component of B to second largest element in A and so on. Can anyone give me a hint how can I do it without using time consuming iterative algorithm?
From: ImageAnalyst on 11 Jan 2010 06:39 Are you sure those are really the sizes of your matrices? Because I don't really consider nanoseconds "time consuming." Now if they were thousands of elements in each direction, then it could be time consuming. Anyway, did you look at sort()?
From: Jan Simon on 11 Jan 2010 07:03 Dear Jan! > I've been programming in Matlab for quite a while now, but recently I ran into a problem that I can't solve in a neat and efficient way. I have a 2D matrix A (lets say 32x32) and a vector B (lets say its length is 16). Now I want to find 16 largest values in matrix A. Then I want to add first component of vector B to largest element in A, second component of B to second largest element in A and so on. Can anyone give me a hint how can I do it without using time consuming iterative algorithm? Have you seen Bruno's MinMax selection function? http://www.mathworks.com/matlabcentral/fileexchange/23576 Usually this is much faster than SORT. Good luck, Jan
From: Jan on 11 Jan 2010 07:12 Size of matrices is just an example - they will be bigger (1024x1024) and this operation will be run thousands of times. Even if it weren't I still want to create my code that is as fast as possible :) I'm afraid sort() (or sortrows() ) won't solve my problem. At least I don't see how I could use these functions. sort()/sortrows() can give me indices of elements in a column/row, but it's possible that 2-nd largest element in column/row 1 is greater than largest element in column/row 2. I need something that gives global results.
From: Jan on 11 Jan 2010 07:13 Size of matrices is just an example - they will be bigger (1024x1024) and this operation will be run thousands of times. Even if it weren't I still want to create my code that is as fast as possible :) I'm afraid sort() (or sortrows() ) won't solve my problem. At least I don't see how I could use these functions. sort()/sortrows() can give me indices of elements in a column/row, but it's possible that 2-nd largest element in column/row 1 is greater than largest element in column/row 2. I need something that gives global results.
|
Next
|
Last
Pages: 1 2 Prev: Gigabit Ethernet Camera - jAi GigE Camera Next: how to create an object in a GUI callback |