I'm studying for an exam and I am stuck on this problem this is what I have so far...

1 回表示 (過去 30 日間)
Allison Sims
Allison Sims 2022 年 8 月 4 日
回答済み: Image Analyst 2022 年 8 月 7 日
  • All of the elements in the first row are the column number +2 and all of the elements in the first column are the row number + 3.
  • All other elements in the matrix are the sum of the value above it and the value to the left of it
row = input('Enter value');
col = input('Enter value');
Mat=zeros(row,col)
for i=1:length(row)
for j = 1:length(col)
if i==1;
Mat(i,col(i)+2)
Mat(j,row(i)+3)
  1 件のコメント
Torsten
Torsten 2022 年 8 月 4 日
All of the elements in the first row are the column number +2 and all of the elements in the first column are the row number + 3.
All of the elements in the first row are the column number +2
Thus Mat(1,1) = 3
all of the elements in the first column are the row number + 3
Thus Mat(1,1) = 4
Contradiction !

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

回答 (1 件)

Image Analyst
Image Analyst 2022 年 8 月 7 日
The first index in a matrix if row and the second is column. In your loops j is the column. So you cannot have the first index be j.
Mat(j,row(i)+3) % NO!!!
"other elements in the matrix are the sum of the value above it and the value to the left of it"
so after you've set up the first row and column, start the loops at 2 and reference the matrix values above and to the left of it
% Add (above current element) + (left of current element) respectively
Mat(i, j) = Mat(i - 1, j) + Mat(i, j-1);

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by