how to create a function ?

조회 수: 4 (최근 30일)
MUKESH KUMAR
MUKESH KUMAR 2017년 10월 4일
답변: Guillaume 2017년 10월 4일
I want to create a function which gives following information like
fi = @(a,b) ([a:data_len 1:b]);
if x<y
A= x:y ;
if x>y
A = fi(x,y);
for example:
if x=6
y= 10
then A= 6 7 8 9 10
but if x= 20 and y=2 like time in a watch
then A= 20 21 22 23 24 1 2
but this function only gives 20 1 2 .
  댓글 수: 1
Rik
Rik 2017년 10월 4일
You are not very clear in what you want, but I would guess the value of data_len was set to 20 instead of 24 when the anonymous function fi was created.

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

채택된 답변

Guillaume
Guillaume 2017년 10월 4일
Assuming that 0 instead of 24 is ok:
data_len = 24;
f = @(a, b) mod(a : b + data_len*(a>b), data_len);
results:
>> f(6,10)
ans =
6 7 8 9 10
>> f(20, 2)
ans =
20 21 22 23 0 1 2

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 10월 4일
Why not
A = rem(x:y, 24)
It's not clear why you have a 24 in there instead of 0. I've never seen 24 used for an hour in a 24 hour clock.

카테고리

Help CenterFile Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by