how to apply a equation to specific row ranges of a vector?
조회 수: 2 (최근 30일)
이전 댓글 표시
If I have two vectors vp and vs, and I want to obtain a vector E which corresponds to this formula:
E = (d*(vs.^2).*(3*(vp.^2))./(vp.^2))./10000;
How could I obtain vector E varying d values with
d1 = 1; %for 1-3 rows
d2 = 2; %for 4-8 rows
d3 = 3; %for 9-10 rows
and obtain
E = [7.66525677840456
35.4506940715996
51.0153087814661
515.455370763582
678.584571443203
699.618989835563
864.000069120001
864.000069120001
1296.00010368000
1296.00010368000];
%%
vp = [340.216815000000;570.718050000000;769.256473000000;1176.42951000000;1632.88855600000;2099.99990500000;2099.99990500000;2099.99990500000;2099.99990500000;2099.99990500000];
vs = [159.846351000000;343.757153000000;412.372440000000;926.872313000000;1063.47274800000;1079.82945400000;1200.00004800000;1200.00004800000;1200.00004800000;1200.00004800000];
d1 = 1;
d2 = 2;
d3 = 3;
E = (d*(vs.^2).*(3*(vp.^2))./(vp.^2))./10000;
댓글 수: 0
채택된 답변
Jacob Shulman
2018년 12월 27일
편집: madhan ravi
2018년 12월 28일
for i=1:10
if i<=3
E(i) = (d1*(vs(i)^2)*(3*(vp(i)^2))/(vp(i)^2))/10000;
elseif i<=8
E(i) = (d2*(vs(i)^2)*(3*(vp(i)^2))/(vp(i)^2))/10000;
else
E(i) = (d3*(vs(i)^2)*(3*(vp(i)^2))/(vp(i)^2))/10000;
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!