フィルターのクリア

How to calculate mean value of a parameter within interval of other parameters

2 ビュー (過去 30 日間)
Laurent Fregosi
Laurent Fregosi 2020 年 6 月 26 日
コメント済み: Laurent Fregosi 2020 年 6 月 26 日
Hi,
The title is perhaps not very clear...
I have a 3 vectors X, Y and Z of same dimension N.
I have also 2 intervals vectors containing the limit of each interval (wich are not necessary equidistant) of X and Y values: int_X (dimension i_X) and int_Y (dimension i_Y).
I want to calculate the mean value of Z for each interval of both int_X and int_Y (each "square" of the (int_X,int_Y) plane), and put the results in a matrix of dimension (i_X,i_Y).
Of course, I can do it with 2 "for" loops, but I would like to find a more elegant method without for loops.

回答 (1 件)

millercommamatt
millercommamatt 2020 年 6 月 26 日
Assuming I've understood your description of your arrays correctly... i.e. that int_X and int_Y contain max and min values for the X and Y bounds respectively. e.g. X_int = [x_min, x_max];
Z_bounded = Z(X>int_X(1) & X<int_X(2) & Y>int_Y(1) & Y<int_Y(2));
mean(Z_bounded(:));
If there are multiple intervals defined, you could put the above in a for loop.
  1 件のコメント
Laurent Fregosi
Laurent Fregosi 2020 年 6 月 26 日
Thanks Matthew.
But in fact, int_X contains sevral boundaries. For example, int_X = [0 1 2 5 10] and int_Y=[0 10 50 100].
I try to have the mean of Z for all the combination of each intervals of int_X and int_Y (for example one mean value will be when X is between 1 and 2 and Y is between 50 and 100, etc... for each combination
Hpe it's clear...

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by