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

1 Ansicht (letzte 30 Tage)
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;

Akzeptierte Antwort

Jacob Shulman
Jacob Shulman am 27 Dez. 2018
Bearbeitet: madhan ravi am 28 Dez. 2018
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by