Change matrix bits depending on the rate (Matlab)

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일

0 개 추천

[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

It works very well. Thank you so much sir
Jan
Jan 2021년 3월 13일
편집: Jan 2021년 3월 13일
You are welcome.
A question: We do not use the expression "sir" in Europe. I assume this term shows respect. Does it sound impolite in your ears, if I or other members of this forum do not use this word?
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개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2021년 3월 13일

댓글:

Jan
2021년 3월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by