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!