Performing what toeplitz does without using pre-installed function

1 回表示 (過去 30 日間)
Losoupbowla
Losoupbowla 2021 年 1 月 29 日
コメント済み: Losoupbowla 2021 年 2 月 1 日
I currently have 8x8 matrix of NaNs. The assignment is to replace all elements of the NaN with numbers 1-8 and then flip them around the way toeplitz function would, without actually using it. We are supposed to use nested for loops and end up with this result:
1 2 3 4 5 6 7 8
2 1 2 3 4 5 6 7
3 2 1 2 3 4 5 6
4 3 2 1 2 3 4 5
5 4 3 2 1 2 3 4
6 5 4 3 2 1 2 3
7 6 5 4 3 2 1 2
8 7 6 5 4 3 2 1
Any idea how to do this? I am completely stuck. So far I only have this
toeplitzSize=8
toeplitz=nan(toeplitzSize)
for a=1:toeplitzSize
for b=1:toeplitzSize
if isnan(toeplitz(a,b))
toeplitz(a,b)= b;
end
end
end
  1 件のコメント
Stephen23
Stephen23 2021 年 2 月 1 日
Note that you should NOT name any variable toeplitz, as this shadows the inbuilt function.

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

採用された回答

Sindhu Karri
Sindhu Karri 2021 年 2 月 1 日
Hiii Losoupbowla,
Hope the below attached code helps
toeplitSize=8;
toeplitz=nan(toeplitSize);
for i=1:toeplitSize
k=i;
for j=1:toeplitSize
if isnan(toeplitz(i,j))
if(j<=i)
toeplitz(i,j)=k;
k=k-1;
else
toeplitz(i,j)=j-i+1;
end
end
end
end

その他の回答 (0 件)

カテゴリ

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