フィルターのクリア

modify a program to obtain the same result from right to left

3 ビュー (過去 30 日間)
high speed
high speed 2021 年 4 月 6 日
コメント済み: Rik 2021 年 6 月 18 日
I have this matrix:
H=[0 1 0 0 0 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 0 0 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 1 0 0;
0 0 0 0 0 0 0 0 0 0 0 1]
I want use but from right to left. It means I want obtain this matrix
H=[0 1 0 0 0 0 0 0 0 0 1 0;
0 0 0 1 0 0 0 0 1 0 0 0;
0 0 0 0 0 1 1 0 0 0 0 0;
0 0 0 0 1 0 0 1 0 0 0 0;
0 0 1 0 0 0 0 0 0 1 0 0;
1 0 0 0 0 0 0 0 0 0 0 1]
  1 件のコメント
Rik
Rik 2021 年 6 月 18 日
I recovered the removed content from the Google cache (something which anyone can do). Editing away your question is considered rude.
modify a program to obtain the same result from right to left
I have this MATLAB program
dr = 6; dc = 3; N = 12; M=6; r=gcd(M,N); c=N/r; b=M/r;
H=zeros(M,N);
%Full rank (left)
vCol = c:c:N;
for iCol = 1:numel(vCol )
iRow = (iCol - 1) * b + 1;
H(iRow:iRow + b - 1, vCol(iCol)) = 1;
end
Using this program I obtain the result of this matrix:
H=[0 1 0 0 0 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 0 0 0;
0 0 0 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 0 1 0 0;
0 0 0 0 0 0 0 0 0 0 0 1]
I want use the same part of Full rank in this program but from right to left. It means I want obtain this matrix
H=[0 1 0 0 0 0 0 0 0 0 1 0;
0 0 0 1 0 0 0 0 1 0 0 0;
0 0 0 0 0 1 1 0 0 0 0 0;
0 0 0 0 1 0 0 1 0 0 0 0;
0 0 1 0 0 0 0 0 0 1 0 0;
1 0 0 0 0 0 0 0 0 0 0 1]
Notice: It's not an identity matrix because it depends on the rate b and c.

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

採用された回答

Rik
Rik 2021 年 4 月 6 日
Your loop can probably be replaced by a vectorized operation, but I will leave that for you to figure out. I suspect fliplr and or() are all you need:
dr = 6; dc = 3; N = 12; M=6; r=gcd(M,N); c=N/r; b=M/r;
H=zeros(M,N);
vCol = c:c:N;
for iCol = 1:numel(vCol )
iRow = (iCol - 1) * b + 1;
H(iRow:iRow + b - 1, vCol(iCol)) = 1;
end
H = double( H | fliplr(H) );
disp(H)
0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1
  2 件のコメント
high speed
high speed 2021 年 4 月 6 日
What do you mean by vectorized operation please
Rik
Rik 2021 年 4 月 14 日
By vectorized opeation I mean something like this:
M=6;N=12;
H=zeros(M,N);
H( (M+1):(2*M+1):end )=1;
disp(H)
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
This way you generate the entire array at once. Careful construction of the vector of indices might avoid a loop. With the exceptions of functions that hide a loop (e.g. cellfun and arrayfun), code without a loop will almost always be faster.

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

その他の回答 (0 件)

カテゴリ

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