How to customize the step of round function?

조회 수: 5 (최근 30일)
Amit Singh
Amit Singh 2018년 6월 14일
댓글: Amit Singh 2018년 6월 15일
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
T=54.3115;
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,
k=max(find(Az-(A(ii)+A(ii+1))/2)<0);
Az(1:k)=A(ii);
end;
end
What is the error I'm doing here?
  댓글 수: 2
Jan
Jan 2018년 6월 14일
You forgot to mention, how the result differs from your expectations. This makes it harder to guess, what the "error" might be.
Amit Singh
Amit Singh 2018년 6월 15일
I eventually figured it out. I only realized it later I failed to describe the true nature of my problem.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2018년 6월 14일
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));
end
See discretize also and maybe the 2nd output of histcounts to do this more efficiently.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by