how to apply a equation to specific row ranges of a vector?

1 次查看(过去 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;

采纳的回答

Jacob Shulman
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by