numel

numel

numel是MATLAB的一個函式,用於計算數組中滿足指定條件的元素個數。若是一幅圖像,則numel(A)將給出它的像素數。

基本介紹

  • 外文名:numel
  • 性質:科學
  • 類別:計算機學
  • 屬於:MATLAB函式
函式簡介,程式示例,

函式簡介

語法格式:
n = numel(A)
返回數組A中元素個數。
n = numel(A, index1, index2, ... indexn)
返回A(index1, index2, ... indexn)中元素的個數,其中indexi可以是切片運算、算術表達式邏輯表達式等。
當一個表達式產生一個由逗號隔開的列表(包括形如A{index1, index2, ..., indexn}這種大括弧括起來的索引列表,或者使用成員操作符進行結構體成員訪問),MATLAB軟體就會隱式調用numel內建函式。
相關函式:size,length

程式示例

>> a = rand(4);
>> a(:, :, 2) = a'
a(:,:,1) =
0.1190 0.5853 0.5060 0.5472
0.4984 0.2238 0.6991 0.1386
0.9597 0.7513 0.8909 0.1493
0.3404 0.2551 0.9593 0.2575
a(:,:,2) =
0.1190 0.4984 0.9597 0.3404
0.5853 0.2238 0.7513 0.2551
0.5060 0.6991 0.8909 0.9593
0.5472 0.1386 0.1493 0.2575
>> numel(a)
ans = 32
>> numel(a, a > 0.15)
ans = 26
>> numel(a, a > 0.8)
ans = 6
>> numel(a, 1:3, 2:4, :)
ans = 18

相關詞條

熱門詞條

聯絡我們