Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: maximum non-zero column index
Replies: 4   Last Post: Mar 4, 2010 3:14 AM

 Messages: [ Previous | Next ]
 Claudio Pedrazzi Posts: 26 Registered: 8/27/09
maximum non-zero column index
Posted: Mar 3, 2010 11:53 AM

Hello everyone,
I don't find a "vector" way to solve the following problem:

given a matrix R, find the highest column index containing a non-zero value. here is my algorithmic solution

function j_max=search_max_non_zero_index(R)
% Searches the maximum column index containing a non null value and returns it

j_max=0;
for i=1:size(R,1)
for j=1:size(R,2)
if R(i,j)~= 0
j_max=max(j_max,j);
end
end
end

I am almost sure that with a good usage of the "any" fuction, some of those loops can be eliminated.

Thanks for any help!
Best regards
Claudio

Date Subject Author
3/3/10 Claudio Pedrazzi
3/3/10 mike zander
3/3/10 mike zander
3/3/10 Walter Roberson
3/4/10 Claudio Pedrazzi