Change matrix bits depending on the rate (Matlab)

2 ビュー (過去 30 日間)
Afluo Raoual
Afluo Raoual 2021 年 3 月 13 日
コメント済み: Jan 2021 年 3 月 15 日
Dear members;
I have matrix of B*C dimensions.
and I have to write a program that verify if the final bits are '0' or '1'. If final bits are '0', the program change them to '1'.

採用された回答

Jan
Jan 2021 年 3 月 13 日
編集済み: Jan 2021 年 3 月 13 日
[s1, s2] = size(A);
d = gcd(s1, s2);
n1 = s1 / d;
n2 = s2 / d;
vCol = n2:n2:s2;
for iCol = 1:numel(vCol)
iRow = (iCol - 1) * n1 + 1;
A(iRow:iRow + n1 - 1, vCol(iCol)) = 1;
end
Alternative - more Matlab'ish without loops:
sizeA = size(A);
n = sizeA ./ gcd(sizeA(1), sizeA(2));
idx = sub2ind(sizeA, 1:sizeA(1), repelem(n2:n2:s2, n1));
A(idx) = 1;
  4 件のコメント
Afluo Raoual
Afluo Raoual 2021 年 3 月 13 日
When someone help us, we appreciate its help using (Sir) to show our respect and greatful for him. But if other persons don't use this expression, it doesn't mean it's impolite. Sometimes saying "Thank you so much" is sufficent.
Jan
Jan 2021 年 3 月 15 日
Thanks for the explanation. It is not trivial to communicate with persons from different cultural regions.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by