Creating 2 new arrays for given condition
조회 수: 1 (최근 30일)
이전 댓글 표시
Good day, I'm trying to write an algorithm that goes as follows:
So I have y values (y) and corresponding time values (tTrans). I want to make new arrays with one of them being y values only greater than 0.0004 and another with it's corresponding time values. however I keep getting the error:
Please help and thanks in advance!
#######################################################
Array indices must be positive integers or logical
values.
Error in Practical1 (line 74)
yn(i)=yT(r(i));
#######################################################
Let y be a [n,1] size array
let tTrans be a [1,n] size array
########################################CODE##########################################
for i=1:length(y)
if abs(yT(i))>0.0004
n=n+1; % Get the array posistions where y>0.001 for speech, creating n, which is the size of my second arrays.
end
end
r = zeros(1,n);
yn= zeros(1,n); %Initializing sizes of my second arrays
tT= zeros(1,n);
for i=1:n
if abs(yT(i))>0.0004;
for j=1:n
r(j)=i; % Get the array posistions where y>0.001
end
end
end
pause;
for i=0:n
yn(i)=yT(r(i)); %Wanting to create a new array, with all the y-values greater than 0.004;
tT(i)=tTrans(r(i)); %Wanting to create a new array, for the time values corresponding to values greater than 0.004;
end
yn=transpose(yn);
hold off;
plot(tT,yn);
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!