저는 교수님을 위해 제 RA 업무를 거의 마쳤습니다. 그러나, 나는 프로그래밍 문제를 가지고있다. 교수가 저에게 요구 한 구현의 마지막 단계는 행렬에 대해 쓴 모든 함수를 실행해야한다는 것입니다. 어떤 일이 일어날 것은 그 행렬의 각 열에 대해, 내가 예를 들어, 다음과 같습니다 내가 쓴 함수를 호출하는 것입니다 : 이제행렬의 각 열에 대해 함수를 실행하도록 MATLAB에 요청하는 방법은 무엇입니까?
function [xpeaks, xtroughs]=peaktrough(x,cutoff)
% This function is a modified version of the algorithm used to identify
% peaks and troughs in a series of prices. This will be used to identify
% the head and shoulders algorithm. The function gives you two vectors:
% PEAKS - an indicator vector that identifies the peaks in the function,
% and TROUGHS - an indicator vector that identifies the troughs of the
% function, and a MATRIX - ptdata, which is a matrix of the location and
% the value of the peak/trough.
% The input is the vector of exchange rate series, and the cutoff
% used for the selection of the final peaks and troughs.
% Finding all possible peaks and troughs of our vector.
[posspeak,possploc]=findpeaks(x);
[posstrough,posstloc]=findpeaks(-x);
posspeak=posspeak';
posstrough=posstrough';
% Initialize vector of peaks and troughs.
numobs=length(x);
prelimpeaks=zeros(numobs,1);
prelimtroughs=zeros(numobs,1);
numpeaks=numel(possploc);
numtroughs=numel(posstloc);
% Indicator for possible peaks and troughs.
for i=1:numobs
for j=1:numpeaks
if i==possploc(j);
prelimpeaks(i)=1;
end
end
end
for i=1:numobs
for j=1:numtroughs
if i==posstloc(j);
prelimtroughs(i)=1;
end
end
end
% Vector that gives location.
location=1:1:numobs;
location=location';
% From the list of possible peaks and troughs, find the peaks and troughs
% that fit Chang and Osler [1999] definition.
% "A peak is a local minimum at least x percent higher than the preceding
% trough, and a trough is a local minimum at least x percent lower than the
% preceding peak." [Chang and Osler, p.640]
peakcutoff=1.0+cutoff; % cutoff for peaks
troughcutoff=1.0-cutoff; % cutoff for troughs
% First peak and first trough are initialized as previous peaks/troughs.
prevpeakloc=possploc(1);
prevtroughloc=posstloc(1);
% Initialize vectors of final peaks and troughs.
vectpeak=zeros(numobs,1);
vecttrough=zeros(numobs,1);
% We first check whether we start looking for peaks and troughs.
for i=1:numobs
if prelimpeaks(i)==1;
if i>prevtroughloc;
ratio=x(i)/x(prevtroughloc);
if ratio>peakcutoff;
vectpeak(i)=1;
prevpeakloc=location(i);
else vectpeak(i)=0;
end
end
elseif prelimtroughs(i)==1;
if i>prevpeakloc;
ratio=x(i)/x(prevpeakloc);
if ratio<troughcutoff;
vecttrough(i)=1;
prevtroughloc=location(i);
else vecttrough(i)=0;
end
end
else
vectpeak(i)=0;
vecttrough(i)=0;
end
end
% Now from the final peaks and troughs, we now write the matrix of the
% peaks and troughs of the exchange rate series.
xpeaks=find(vectpeak);
xtroughs=find(vecttrough);
end
을 건이다, 그러나, 다른 열의, 나는 다른 크기의 벡터로 끝날 것이다. 내가 알고 싶은 것은, 어떻게 그것에 대해 알 수 있습니까? 20 개의 사용자 작성 함수가 있으며 각 함수에 대해 5000 x 10000 행렬의 각 열을 실행해야합니다.
내 친구가 내 행렬의 n 번째 열을 가져 오는 함수를 작성하고 그 결과 벡터 내 행렬의 각 기능을 실행, 벡터로서 돌려 제안했다. 다른 아이디어? 솔직히 말해서, 나는 그가 제안한 그 기능을 어떻게 쓰는지 모른다. 감사!
당신은, 벡터 사소한 같이 행렬의 N 번째 열을 반환 MTX 친구의 조언을 따르십시오. 그런 다음 각 사용자 정의 함수에 feval()을 사용하십시오. – engineerC
내가 질문에 대답했다고 생각되면 내 대답 옆의 체크 표시를 클릭하여 답을 표시하십시오. 그렇지 않다면 왜 내 대답을 개선 할 수 있는지 알려주십시오. 건배. –
안녕 콜린, 난, 난 당신이 내 질문에 대답했을 수도 죄송 생각 해요,하지만 난 내 컴퓨터가 느리기 때문에 결과를 볼 못하고있다. –