필터 지우기
필터 지우기

How do I create bin widths using a simple algebra function?

조회 수: 1 (최근 30일)
Charlie Finnie
Charlie Finnie 2016년 10월 27일
편집: Massimo Zanetti 2016년 10월 28일
I have currently created a single bin for my vector time(0-5million years) using :
ExtractedData = data(find(time<5),2);
On this bin I have removed the NaN values and calculated the mean and SD. I need to repeat these calculations for bins which are 5-10million years, 10-15millionyears...etc until 540million years. I've been instructed to do this by creating a loop e.g.
for n=1:108
ExtractedData = data(find(time<5),2);
%%%code to remove NaN
%%%code to calculate mean and SD etc
end
and to change the part of the function "time<5" with a function for a maximum and minimum value of time where the minimum is defined by the function 5(n-1) and the maximum defined by 5(n-1)+5.
I was wandering how I can incorporate this into the line of code starting with "ExtractedData"?
Thanks
Charlie

채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 10월 27일
편집: Massimo Zanetti 2016년 10월 27일
IMPORTANT: there is no need to use find!!!
EXPLOIT MATLAB LOGICAL INDEXING
To replace "time<5" with "5<time<10" just use & (and operator) to match the cases where both 5<time AND time<10:
data( (5<time)&(time<10) ,2);
  댓글 수: 2
Charlie Finnie
Charlie Finnie 2016년 10월 28일
okay, thank you. DO you know how to replace "5<time" with a function that will give me values of time which follow the algebra function 5n+1?
Massimo Zanetti
Massimo Zanetti 2016년 10월 28일
편집: Massimo Zanetti 2016년 10월 28일
for an index k, it is k=5n+1 for some n if k-1 is divisible by 5, so
data( rem(time-1,5)==0 ,2);
Of course, this only works if time is vector of integers.

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

추가 답변 (1개)

Steven Lord
Steven Lord 2016년 10월 27일
Rather than building the bins yourself, I recommend using the approach I described in one of your other questions that uses discretize.
  댓글 수: 2
Massimo Zanetti
Massimo Zanetti 2016년 10월 27일
편집: Massimo Zanetti 2016년 10월 27일
Steven, the author of question in the link you posted is the same as here.. so I think he is really interested in knowing how to bin using another approach..
Charlie Finnie
Charlie Finnie 2016년 10월 28일
Hi, yeah I need to create the bins manually (not using discretize) as this is required for the modelling I will be doing on the bins

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by