Assign letters as matrices; inputs

7 ビュー (過去 30 日間)
Patricia  Bracer
Patricia Bracer 2015 年 11 月 10 日
回答済み: Joachim Schlosser 2015 年 11 月 10 日
I try to write a function that takes as its input argument a scalar integer and returns Q, a 2n-by-2n matrix. Q consists of four n-by-n submatrices. The elements of the submatrix in the top left corner are all 1s, the elements of the submatrix at the top right are 2s, the elements in the bottom left are 3s, and the elements in the bottom right are 4s. My main problem is that I do not know how to assign 's' in the matrix. Any help will be appreciated
function Q = quadrants( n )
M=zeros(2*n)
s = sym('s')
for i=1:n
for j=1:n
M(i,j)=s
end
end
for i=1:3
for j=(n+1): end
M(i,j)=2*s
end
end
for i=(n+1):2*n
for j=1:n
M(i,j)=3*s
end
end
for i=(n+1):2*n
for j=(n+1):2*n
end
end
end
  3 件のコメント
dpb
dpb 2015 年 11 月 10 日
Why not move this to Answer so OP can accept it?
Guillaume
Guillaume 2015 年 11 月 10 日
Possibly because the OP question is about symbolic variables.

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

回答 (1 件)

Joachim Schlosser
Joachim Schlosser 2015 年 11 月 10 日
You need to create the matrix as a symbolic matrix:
M=sym('s',[n,n])

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by