How to delete element from a vector in the beginning and last part of my signal
163 次查看(过去 30 天)
显示 更早的评论
Hi everybody, I'm trying to find a way to cut my signals (in the initial and final part). I've found something that works for my main vector but then, when I try to cut other vector in the same way using the indexes I get some problems. That's the code that I'm using:
Stress1= Stress(1:40,:);
Stress2= Stress(41:end,:);
goodIndexes = Stress1 <10 & Stress1>0 ;
goodSignal = Stress(goodIndexes);
goodIndexes2= Stress2 > 5;
goodSignal2= Stress2(goodIndexes2);
Stress_fin= vertcat(goodSignal, goodSignal2);
Disp_1= Displacement (goodIndexes);
*Disp_2= Displacement (goodIndexes2);*
Disp_fin= vertcat (Disp_1, Disp_2);
Force_1= Force (goodIndexes);
*Force_2= Force (goodIndexes2);*
Force_fin= vertcat (Force_1, Force_2);
Eyy_1= Eyy (goodIndexes);
*Eyy_2= Eyy (goodIndexes2);*
Eyy_fin= vertcat (Eyy_1, Eyy_2);
While I obtain what I want for the "Stress" vector, I'm not able to get the same result for the other three vectors because the second vector of each other signal ( Displacement_2, Eyy_2, Force_2) restart from the first index of the father vector and not fromt the index "41" and so I can't get what I want.
Any advice to overcome that problem?
Thanks in advance.
Danilo
0 个评论
采纳的回答
Guillaume
2017-10-13
Note: A good way to find out what is going wrong with your code is to use the debugger and closely watch how your variables evolve as you step through each line.
Yes, clearly your code is not going to work. You split your stress vector into 2, Stress1 is indices 1 to 41 (hence length 41) and Stress2 is indices 42 to end (length unknown, let's call it x, its value does not matter).
You then filter these 2 vectors and obtain two logical vectors of length 42 and x which you use to filter the split vectors. So that works fine
But you also use the logical vectors to filter the complete displacement and force vector. Hence with your first logical vector, you're filtering the first 41 elements, with your second you're filtering the first x elements. In each case, you're filtering from the start. The solution is to concatenate your logical vectors:
Stress1= Stress(1:40,:);
Stress2= Stress(41:end,:);
goodIndexes1 = Stress1 <10 & Stress1>0 ;
goodIndexes2 = Stress2 > 5;
goodIndexes = [goodIndexes1; goodIndexes2]; %concatenate the two logical vectors
Stress_fin = Stress(goodIndexes);
Disp_fin = Displacement(goodIndexes);
Force_fin = Force (goodIndexes);
Eyy_fin = Eyy(goodIndexes);
更多回答(1 个)
KSSV
2017-10-13
vec = rand(!00,1) ; % be your vector/ signal
vec(1)= [] ; % removes the beginning i.e the first element
vec(end) = [] ; % removes the end i.e the last element
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Stress and Strain 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!