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

 채택된 답변

Rik
Rik 2019년 3월 13일

1 개 추천

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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2019년 3월 13일

댓글:

2019년 3월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by