필터 지우기
필터 지우기

More efficient way of this code?

조회 수: 1 (최근 30일)
Dimitrios
Dimitrios 2014년 5월 17일
답변: Image Analyst 2014년 5월 18일
Lets say that i have a function : y=fun(x,z) that do the following calculations :
ex1:
fun([0 45 90],2) , y=[0 45 90 0 45 90]
ex2:
fun([0 45 90],3) , y=[0 45 90 0 45 90 0 45 90]
My code is the following :
Initialx=x;
for ii = 2:z
x=[x Initialx];
end
Is there a more efficient way to do it ? a vectorized or gennerally another way to impliment it?

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 5월 17일
편집: Andrei Bobrov 2014년 5월 18일
fun1 = @(v,n)repmat(v,1,n)

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 5월 18일
% Setup/initialize.
x = [0 45 90]
z = 3 % or 2 or whatever you want.
% Now get your y output:
y = repmat(x, [1,z])

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by