From: Natalie Sin Hwee on 19 Jun 2010 14:24 Dear Mathwork users I have a 1000x1000 matrix with values between 0-1. How can i find the non-zero minimum from each column? I've tried using min but that gives me all zeros Thanks Natalie^^
From: Matt Fig on 19 Jun 2010 14:34 One approach: % Example data: A = round(rand(6,6)*3) % Get the non-zero mins A(~A) = nan; col_mins = min(A)
From: Natalie Sin Hwee on 19 Jun 2010 14:58 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hvj2it$irj$1(a)fred.mathworks.com>... > One approach: > > > % Example data: > A = round(rand(6,6)*3) > > % Get the non-zero mins > A(~A) = nan; > col_mins = min(A) Dear Matt, that worked perfectly!! just what i wanted!! Thank you!! Natalie
From: Matt J on 19 Jun 2010 15:27 > % Get the non-zero mins > A(~A) = nan; > col_mins = min(A) I've been advised in past threads that NaN processing is a lot slower than Infs. It would be advisable to use A(~A) = inf; instead.
From: Matt Fig on 19 Jun 2010 17:36 Wow, you weren't joking Matt! As far as the writing is concerned, there is not much difference. But for MATLAB to deal with the array, BIG DIFFERENCE. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [] = nan_inf() % Is dealing with infs faster than writing nans? t = 0; for ii = 1:100 A = round(rand(1000)); tic A(~A) = nan; colmins = min(A); t = t + toc; end fprintf('Time for the nans is: %.3f seconds.\n',t) t = 0; for ii = 1:100 A = round(rand(1000)); tic A(~A) = inf; colmins = min(A); t = t + toc; end fprintf('Time for the infs is: %.3f seconds.\n',t) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >> nan_inf Time for the nans is: 16.497 seconds. Time for the infs is: 4.969 seconds. >> nan_inf Time for the nans is: 16.300 seconds. Time for the infs is: 4.951 seconds. >> On winvista 32 using 2007b and an old laptop.
|
Pages: 1 Prev: element-by-element multiplication Next: Error while trying to use cwt.m in wavelet toolbox 2.2 |