How to convert continuous variable into discrete variables?
古いコメントを表示

I am looking for the help !!
I have 5000 rows of data points for three variables (independent variables-X1,x2,x3 and dependent variables Y). The x1 and x2 are discreate variables in fix steps. However, the X3 variables is countinous ranges from 0-0.6. I want to transfrom this varibles in steps of 0.05 upto 0.6 total in 12 steps and corroespoing value of Y variables should be mean of all values correspond between 0- 0.05 and so.
Well, i tried with find(x3<0.05) and got the index of all values which is less than 0.05. but struggling to compute mean(y) for the indices, mostly they are continous.
Plz help me.
採用された回答
その他の回答 (3 件)
Alan Stevens
2020 年 8 月 23 日
Does the following do what you want?
X3 = 0:0.05:0.6;
Ydiscrete = zeros(length(X3));
for i = 2:length(X3)
ix = find(X3(i-1)<=x3<X3(i));
Ydiscrete(i) = mean(Y(ix));
end
Untested, as I don't have the data!
Alan Stevens
2020 年 8 月 24 日
How about this
load('DATA.mat');
X3(1) = []; % the first values for X3 and Y are NaNs, so they are removed here
Y(1) = [];
x3 = (0:0.05:0.6)';
Ydiscrete = zeros(length(x3),1);
for i = 2:length(x3)
ix = find(x3(i-1)<=X3<x3(i));
Ydiscrete(i) = mean(Y(ix));
end
plot(x3,Ydiscrete,'o')
Cris LaPierre
2020 年 8 月 24 日
編集済み: Cris LaPierre
2020 年 8 月 26 日
0 投票
3 件のコメント
Chetan Badgujar
2020 年 8 月 24 日
Chetan Badgujar
2020 年 8 月 24 日
Chetan Badgujar
2020 年 8 月 24 日
カテゴリ
ヘルプ センター および File Exchange で Resampling Techniques についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
