필터 지우기
필터 지우기

Creating 2 new arrays for given condition

조회 수: 1 (최근 30일)
Leon Ellis
Leon Ellis 2021년 9월 4일
댓글: Leon Ellis 2021년 9월 4일
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);

채택된 답변

the cyclist
the cyclist 2021년 9월 4일
keepIndex = y>0.0004;
y_new = y(keepIndex);
tTrans_new = tTrans(keepIndex)
  댓글 수: 1
Leon Ellis
Leon Ellis 2021년 9월 4일
Thank you very much! You're a life saver

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by