Iteratively solving using a for loop

Hi there,
I am trying to find the wind shear using the equation (V/Vo) = (H/Ho)^(W) Where W is wind shear.
As of now, I can do it but the for loop using the solve function runs for about 15 minutes to yield 4462 values. WSA490m and WSA3860m are data values enclosed in a csv file, with wind speeds at 49.0m and 38.60m.
if true
Vratio1 = ones(4462,1);
Vratio2 = ones(4462,1);
Hratio1 = (49.0/38.60);
Hratio2 = (59.40/38.60);
LHR1 = log(Hratio1);
LHR2 = log(Hratio2);
WS1 = ones(4462,1); %Wind Shear exponent with 38.60m as reference and 49.0m as the second point
WS2 = ones(4462,1); %Wind Shear exponent with 38.60m as reference and 59.40m as the second point
if true
for r = (1:4462)
Vratio1(r) = (WSA490m(r)/WSA3860m(r));
end
end
if true
for r = (1:4462)
WS1(r) = solve(x == log(Vratio1(r))/LHR1,x);
end
end

回答(1 个)

Hi Rnle,
In Matlab you can divide vectors term-by-term with the ./ command to obtain Vratio1. Then, since
W = solve(x = something,x) is the same as W = something
you can determing WS1 in the following way.
WSA490m = rand(4462,1);
WSA3860m = rand(4462,1);
Hratio1 = (49.0/38.60);
Hratio2 = (59.40/38.60);
LHR1 = log(Hratio1);
LHR2 = log(Hratio2);
Vratio1 = WSA490m./WSA3860m;
WS1 = (log(Vratio1)/LHR1);
The two data vectors should be brought into the workspace as complete 4462x1 vectors. After that is done, the rest of it all happens in a couple of milliseconds.

2 个评论

Thank you! Works like a dream
@Rnle —
Since David Goodmanson’s Answer solved your problem, it is appropriate to Accept it.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

提问:

2018-3-7

Community Treasure Hunt

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

Start Hunting!

Translated by