min/max/mean without matlab functions

3 ビュー (過去 30 日間)
Dudy
Dudy 2014 年 1 月 5 日
コメント済み: Steven Lord 2023 年 2 月 28 日
Hi all. I need to write a code that will give me the min/max value of a certain random matrix(150X200), without the use of matlab built in functions. Can anyone assist me please?
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 5 日
What have you done so far?
Image Analyst
Image Analyst 2014 年 1 月 5 日
It's only like 10 lines of code? What sort of assistance do you want, that we can give without actually giving you the lines of code? Someone tagged it with for and if - yes, you'll need those. What other help can we give?

サインインしてコメントする。

回答 (1 件)

Amith
Amith 2023 年 2 月 28 日
As per my understanding you wanted to know how to find min max and mean of the numbers in a random matrix without using built in functions. Below is the code for doing the same.
% Generate random matrix
rows = 150;
cols = 200;
matrix = rand(rows, cols);
% Initialize minimum and maximum values
min_val = matrix(1,1);
max_val = matrix(1,1);
mean_val = 0;
sum = 0;
% Iterate through matrix to find minimum and maximum values
for i = 1:rows
for j = 1:cols
if matrix(i,j) < min_val
min_val = matrix(i,j);
end
if matrix(i,j) > max_val
max_val = matrix(i,j);
end
sum = sum + matrix(i,j);
end
end
total = rows*cols;
mean_val = sum / total;
% Display results
fprintf('mean value of all the elements in the matrix is %f\n',mean_val);
fprintf('Minimum value: %f\n', min_val);
fprintf('Maximum value: %f\n', max_val);
  1 件のコメント
Steven Lord
Steven Lord 2023 年 2 月 28 日
By a strict reading of this question your code does not satisfy the requirements. The < and > operators are built-in functions, specifically lt, < and gt, >.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by