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 个)
David Goodmanson
2018-3-7
编辑:David Goodmanson
2018-3-7
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 个评论
Rnle
2018-3-8
Star Strider
2018-3-8
@Rnle —
Since David Goodmanson’s Answer solved your problem, it is appropriate to Accept it.
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!