Calculation between different columns

2 ビュー (過去 30 日間)
sannatlegend
sannatlegend 2016 年 11 月 6 日
コメント済み: Star Strider 2016 年 11 月 6 日
Hello,
I am doing a MATLAB program that calculates the wind shear exponent of different heights. I have a matrix of size 2 by 12 that shows the dates and the wind speeds (WS) at a particular height. The titles of the different columns are shown below. In the second row (not shown) there is the date and the wind speed values.
Date WS@200m WS@150m WS@100m WS@80m WS@60m ...
WS@50m WS@40m WS@30m WS@38m WS@20m WS@10m
Now what I want to do is to find the wind shear exponent (alpha) using the following formula:
alpha=log(u1/u2)/log (h1/h2)
where the u stands for wind speed and h stands for height.
And I have to do this for all different combinations of heights, that is, the 200m with 150m, 200m with 100m, 200m with 80m .... and so on, the last one being 20m with 10m.
I am a beginner in MATLAB and am having trouble doing this. If someone could point me in the right direction by telling me which commands to use, it would be appreciated.

採用された回答

Star Strider
Star Strider 2016 年 11 月 6 日
This is relatively straightforward with the bsxfun function. Here, there are two calls to it, one for the altitude and one for the wind velocities. Each creates a matrix of its arguments, so that the structure of ‘u_ratios’ for example is:
u(1)/u(1) u(2)/u(1) ...
u(1)/u(2) u(2)/u(2)
u(1)/u(3) u(2)/u(3)
: .
: .
with the corresponding structure for ‘h_ratios’. The ‘alpha’ calculation then dies element-wise division of these the log of each matrix, producing the output. Note: the diagonals of ‘alpha’ are NaN because they are the results of log(1)/log(1) = 0/0 = NaN. So you may want to eliminate the NaN values on the main diagonal of ‘alpha_mtx_nan’. I did this by creating ‘alpha_mtx’ with -1 on the main diagnonal instead. The NaN values will cause problems with the calculations, so use either matrix. I opted not to ‘collapse’ the matrix by eliminating the main diagonal.
The Code:
u = sort(randi(25, 1, 11), 'descend'); % Create Wind Velocities (m/s)
h = [200 150 100 80 60 50 40 30 38 20 10]; % Altitude (m)
u_ratios = bsxfun(@rdivide, u, u'); % Divide ‘Rows’ Of ‘u’ By Columns Of ‘u'’
h_ratios = bsxfun(@rdivide, h, h'); % Divide ‘Rows’ Of ‘h’ By Columns Of ‘h'’
alpha_mtx_nan = log(u_ratios) ./ log(h_ratios);
alpha_mtx = triu(alpha_mtx_nan,1) + tril(alpha_mtx_nan,-1) + diag(-ones(1,size(alpha_mtx_nan,1),1));
  4 件のコメント
sannatlegend
sannatlegend 2016 年 11 月 6 日
Thank you for your help.
Star Strider
Star Strider 2016 年 11 月 6 日
My pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by