フィルターのクリア

Need Help Creating a loop

3 ビュー (過去 30 日間)
Giovanni Principato
Giovanni Principato 2021 年 3 月 17 日
回答済み: David Hill 2021 年 3 月 17 日
I am kind of new at creating matlab loops and just needed help on this question.
Use loops to create a m x n Matrix named Mat in which the value of each element is the sum of its row number and its column number divided by the square of its column number. For example, the value of element (2,3) is (2+3)/3^2.
m is the number of rows and n is the number of columns. Code has already been provided to assign m and n psuedo-random integer values between 5 and 15. Suppress all statements inside the loop and use a disp command to output the final matrix after the loop.
I am given this:
m = randi([5,15]);
n = randi([5,15]);
%Create a m x n matrix using for loop.
%The elements has to be (row number+column number)/(square of column number)
I have created this and idk how to create it into a matrix.
Mat = [m,n]
[R,C] = size(Mat)
for row = 1:R
for col = 1:C
Mat(row,col) = Mat((R+C)/C^2,(C+R)/C^2)
end
end
disp(Mat)

回答 (1 件)

David Hill
David Hill 2021 年 3 月 17 日
m = randi([5,15]);
n = randi([5,15]);
mat=zeros(m,n);
for row=1:m
for col=1:n
mat(row,col)=(row+col)/col^2;
end
end
display(mat);

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by