複製鏈接
請複製以下鏈接發送給好友

numel

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

numel函數簡介

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

numel程序示例

>> 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