MATLAB Answers


How to customize the step of round function?

Asked by Amit Singh on 14 Jun 2018
Latest activity Commented on by Amit Singh on 15 Jun 2018
Accepted Answer by Jan
I have a matrix of an increasing array of numbers, and I want to round this to the steps given in another matrix.
if true
Az=(0:89)/T; %array of numbers which I want to be rounded
A = [0:5:45 55 65 80]; %matrix giving the integer to which the number from Az must be rounded to
for ii=1:length(A)-1,
What is the error I'm doing here?


You forgot to mention, how the result differs from your expectations. This makes it harder to guess, what the "error" might be.
I eventually figured it out. I only realized it later I failed to describe the true nature of my problem.

Sign in to comment.

1 Answer

Answer by Jan
on 14 Jun 2018
 Accepted Answer

Do you want this:
T = 54.3115;
Az = (0:89)/T; %array of numbers which I want to be rounded
A = [0:5:45 55 65 80];
for k = 1:length(Az)
Az(k) = A(find(A > Az(k), 1));
See discretize also and maybe the 2nd output of histcounts to do this more efficiently.


Sign in to comment.