Reducing every value of a matrice every time by the same value
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am new at matlab and I have a question. Is it possible to reduce every single value of a nx2 matrix by the same amount until all values are zero? Maybe in a for loop?
3 Kommentare
dpb
am 10 Jun. 2021
Of course. Math operations by constants on arrays work on the entire array by default.
Of course, hitting zero exactly would require a specific value that is evenly divisible into the original value without rounding so it may or may not work out exactly depending upon the values in the array.
Or, of course, if the values in the array aren't the same, you'd have to compute that difference by dividing by the number of iterations and then do array addition/subtraction which is also array-wide.
Again, floating point rounding can make hitting exactly zero tricky...
John D'Errico
am 11 Jun. 2021
Please don't keep on asking the same question. If you want more about this question, then make a comment to Matt's answer, asking him for clarification.
Antworten (1)
Matt J
am 10 Jun. 2021
Bearbeitet: Matt J
am 10 Jun. 2021
This might be what you want, but as @Scott MacKenzie says you've left a lot of problem details and issues for us to guess,
while any(matrix(:)>0)
matrix=max(matrix-something,0);
end
4 Kommentare
dpb
am 11 Jun. 2021
Oh. I see I just duplicated Matt's answer that was already there...I had just read the comments before.
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!