怎樣計(jì)算數(shù)組元素的個(gè)數(shù)?
countif(range,criteria)是條件計(jì)數(shù)函數(shù),第一個(gè)參數(shù)是數(shù)據(jù)區(qū)域,第二個(gè)參數(shù)是條件,函數(shù)返回的是數(shù)據(jù)區(qū)域中滿(mǎn)足條件的數(shù)據(jù)的個(gè)數(shù)。
1.先用普通函數(shù)進(jìn)行運(yùn)算,我們輸入函數(shù)=countif(A1:B7,C1),計(jì)算的是A1:B7內(nèi)=C1的數(shù)據(jù)的個(gè)數(shù),A1:B7中等于1的個(gè)數(shù)是4個(gè),所以此函數(shù)返回的結(jié)果是4;
2.再用一維數(shù)組進(jìn)行運(yùn)算,選中F1:F7單元格,輸入函數(shù)=countif(A1:B7,C1:C7),ctrl+shift+enter輸入,計(jì)算的是A1:B7內(nèi)分別等于C1、C2...C7的數(shù)據(jù)的個(gè)數(shù),所以此函數(shù)返回的結(jié)果是7個(gè)數(shù)據(jù),也就是一維數(shù)組{4;4;2;2;4;4;2};
3.再用二維數(shù)組進(jìn)行運(yùn)算,選中F1:G7單元格,輸入函數(shù)=countif(A1:B7,C1:D7),ctrl+shift+enter輸入,計(jì)算的是A1:B7內(nèi)分別等于C1、C2...C7、D1、D2...D7的數(shù)據(jù)的個(gè)數(shù),所以此函數(shù)返回的結(jié)果是14個(gè)數(shù)據(jù),也就是二維數(shù)組{4,4;4,4;2,2;2,2;4,4;4,4;2,2};
4.這里說(shuō)下在數(shù)組內(nèi)逗號(hào)和分號(hào)的作用,逗號(hào)代表行維度,比如{1,2,3,4}在excel里面是1行4列,分號(hào)代表的是列維度,比如{4;4;2;2;4;4;2}在excel里面是7行1列;
5.再看數(shù)組運(yùn)算,選中F1:G7單元格,輸入函數(shù)=1/countif(A1:B7,C1:D7),就=1/{4,4;4,4;2,2;2,2;4,4;4,4;2,2},數(shù)組與常量進(jìn)行加減乘除運(yùn)算,是數(shù)組內(nèi)的每個(gè)元素與常量進(jìn)行加減乘除運(yùn)算,返回的結(jié)果是{0.25,0.25;0.25,0.25;0.5,0.5;0.5,0.5;0.25,0.25;0.25,0.25;0.5;0.5};
6.進(jìn)行就和運(yùn)算,選中F1單元格,輸入函數(shù)=sum(1/countif(A1:B7,C1:D7)),就=sum({0.25,0.25;0.25,0.25;0.5,0.5;0.5,0.5;0.25,0.25;0.25,0.25;0.5;0.5}),返回的結(jié)果為5。
如果還有疑問(wèn),可以回復(fù)哈,再幫忙解答~
如果解決了問(wèn)題,幫忙給個(gè)贊和關(guān)注哈~