Logical मूल्य numeric मानों की तुलना में कम बाइट्स लेते हैं, जो एक प्लस है यदि आप बहुत बड़े सरणी से निपट रहे हैं। आप logical indexing करने के लिए लॉजिकल एरे का भी उपयोग कर सकते हैं। उदाहरण के लिए:
>> valArray = 1:5; %# Array of values
>> numIndex = [0 1 1 0 1]; %# Numeric array of ones and zeroes
>> binIndex = logical([0 1 1 0 1]); %# Logical array of ones and zeroes
>> whos
Name Size Bytes Class Attributes
binIndex 1x5 5 logical %# 1/8 the number of bytes
numIndex 1x5 40 double %# as a double array
valArray 1x5 40 double
>> b = valArray(binIndex) %# Logical indexing
b =
2 3 5
>> b = valArray(find(numIndex)) %# You have to use the FIND function to
%# find the indices of the non-zero
b = %# values in numIndex
2 3 5
एक ध्यान दें: आपको लगता है कि बहुत विरल (यानी बहुत कम वाले) हैं शून्य और लोगों की सरणियों के साथ काम किया जाएगा है, यह इस तरह के रूप संख्यात्मक सूचकांक की एक सरणी का उपयोग करने के लिए सबसे अच्छा हो सकता है आपको FIND फ़ंक्शन से प्राप्त होगा। निम्नलिखित उदाहरण लें:
>> binIndex = false(1,10000); %# A 1-by-10000 logical array
>> binIndex([2 100 1003]) = true; %# Set 3 values to true
>> numIndex = find(binIndex) %# Find the indices of the non-zero values
numIndex =
2 100 1003
>> whos
Name Size Bytes Class Attributes
binIndex 1x10000 10000 logical %# 10000 bytes versus
numIndex 1x3 24 double %# many fewer bytes
%# for a shorter array
बहुत अच्छा जवाब! – Elpezmuerto