Info
This question is closed. Reopen it to edit or answer.
Looping and printing matrix
1 view (last 30 days)
Show older comments
if A=[2;4;6;8;6;7]. B=1
C=A-B,
C will become, [1;3;5;7;5;6], since one of the elements of C is 1 or less than one, Z1=B(current)
again i will increase B=2
now C = [0;2;4;6;4;5] since it is the same element which is zero, i want to ignore B(current).
again i will increase B=3
now C = [-1;1;3;5;3;4]. since one more element is equal or less than 1, Z2=B(current)
like this i want to do continously.
How to achieve this.
Any help will be appreciated.
Thanks.
0 Comments
Answers (1)
Image Analyst
on 1 Nov 2014
When do you stop? Eventually all elements will be 1 or less so you'll just keep increasing B forever and all elements of C will end up moving towards minus infinity. Do you stop when all elements are 1 or less? If so, why not just do
C = A - max(A(:)) + 1;
and not use a loop at all?
2 Comments
Image Analyst
on 1 Nov 2014
You will never have all the elements be 1 if you are subtracting the same number from each element. Just think about it. You will never ever arrive at C=[1,1,1,1,1] by subtracting the same number from [2;4;6;8;6;7].
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!