Define permutation map on {1,2,3}

조회 수: 3 (최근 30일)
Reza Yaghmaeian
Reza Yaghmaeian 2022년 2월 26일
답변: Voss 2022년 2월 26일
I want to define a function which .
How could I do this?

답변 (1개)

Voss
Voss 2022년 2월 26일
% you can index into a vector:
S_vec = [2 3 1];
% or you can define an anonymous function:
S_func = @(x)mod(x,3)+1;
% they work the same:
S_vec(1)
ans = 2
S_vec(2)
ans = 3
S_vec(3)
ans = 1
S_func(1)
ans = 2
S_func(2)
ans = 3
S_func(3)
ans = 1
% and both work for vector inputs:
S_vec([1 2 3])
ans = 1×3
2 3 1
S_func([1 2 3])
ans = 1×3
2 3 1

카테고리

Help CenterFile Exchange에서 Holidays / Seasons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by