For Loop /Array question
古いコメントを表示
How would i go about creating a for loop to create an array where each value in X is equal to its associated row value * 2 plus its associated column value * 3 +1. Size of array is 50x50 ?
2 件のコメント
James Tursa
2020 年 2 月 3 日
What have you done so far? What specific problems are you having with your code? Do you know how to write a for-loop? Do you know how to pre-allocate a 50x50 matrix?
Tyler Young
2020 年 2 月 4 日
採用された回答
その他の回答 (1 件)
KSSV
2020 年 2 月 4 日
Check the below deom code where each element of a matrix is sum of its row and column position. Extend this to your case.
m = 5 ; % number of rows
n = 5 ; % number of columns
iwant = zeros(m,n) ; % initialize the required matrix
% loop
for i = 1:m % loop for row
for j = 1:n % loop for column
iwant(i,j) = i+j ; %(i,j)th element is sum of i and j
end
end
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!