Average of a single element in an array
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
Im generating random numbers between (1 and 2) in 2D array. I want to get the average times of getting number (1) in the array. i tried to use M = mean(1,'all') and M = mean(1) but it didnt work out.
Thanks
0 件のコメント
採用された回答
Rik
2019 年 3 月 13 日
The best method depends on how you have generated your array. I will show two examples below.
%example 1: only integers
A=randi(2,200,200);
fraction_of_ones= sum(A==1,'all')/numel(A);
%example 2: non-integers as well
A=randn(200,200)+1.5;A(A<1)=1;A(A>2)=2;
tolerance=1e-3;
fraction_of_ones= sum(abs(A-1)<=tolerance,'all')/numel(A);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!