Change the sign of a Vector over N intervals
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi everyone,
I'm new to Matlab, my question may be super easy….I want to get a vector (Ytot ) witch is composed of the same function but with different signs set on différents intervals , that's not a problem for 2 or 3 vectors , but i dont know how to manage it with n intervals ?
This is an example :
Y = function_example;%%%% (define on 1 : 100)
T = [1; 9 ;17 ;...….89; 100] ;%%%(for example 24values)
A = [-1; 1 ; 1; ......…..-1]; %%% signs for each intervals
Y1 = -1*Y(1:9); %%% equal to Y between 1 and 9, and equal to 0 between 10 and 100
Y2 =1*Y(9:17);
Y24 =-1*Y(89:100);
t1 = (1: 1: 9);
t2 = (9: 1: 17);
tn = (89 :1: 100);
Ttot = [t1 +t2+...t24];
Ytot = [Y1 + Y2 + ….Y24];
댓글 수: 0
답변 (1개)
Rafael Hernandez-Walls
2021년 3월 31일
Use something like this:
Y=rand(1,20);
d=[1:4,8:12,17:20];
Y(d)=-Y(d)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!