generate a matrix with numbers between [0,1]
1 次查看(过去 30 天)
显示 更早的评论
I have to generate a matrix of n x n uniformly distributed random numbers (n read from keyboard). The numbers should be between [0,1] and then to average the numbers > 0.5. I've tried the following:
value = 'Insert a value for n: ';
x = input(value);
matrix = rand(x,x);
matrix2(matrix < 0.5) = nan;
average = mean(matrix2, 'omitnan');
disp(average);
0 个评论
回答(1 个)
KSSV
2022-1-11
value = 'Insert a value for n: ';
x = input(value);
matrix = rand(x,x);
matrix2 = matrix ; % you need to create matrix2
matrix2(matrix < 0.5) = nan;
average = mean(matrix2, 'omitnan');
disp(average)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!