フィルターのクリア

how to create a function from a script

3 ビュー (過去 30 日間)
Niya Bedzheva
Niya Bedzheva 2019 年 9 月 18 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 18 日
hello, could anyone help with transforming this code into a matfile function so i can apply for different kind of data in my script.
y = drying_rate_1;
x = Zeit(~isnan(y));
y = y(~isnan(y));
[p,err] = polyfit(x,y,1);
fit_orig = polyval(p,x);
y_tilde = y - fit_orig;
quants = quantile(y_tilde, 100);
indices = [];
for i = 1:length(y_tilde)
if((y_tilde(i) > quants(2)) && (y_tilde(i) < quants(end - 1)))
indices = [indices; i];
end
end
x_filter = x(indices);
y_filter = y(indices);
[p,err] = polyfit(x_filter,y_filter,1);
y_fit = polyval(p,x_filter);
figure(3);
plot(x_filter, y_filter, x_filter, y_fit)

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 18 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 18 日
Is this? Pass the different input arguments (y=drying_rate_1) to the function, as a result you will get the different plots as per y data.
function test1(y)
x = Zeit(~isnan(y));
y = y(~isnan(y));
[p,err] = polyfit(x,y,1);
fit_orig = polyval(p,x);
y_tilde = y - fit_orig;
quants = quantile(y_tilde, 100);
indices = [];
for i = 1:length(y_tilde)
if((y_tilde(i) > quants(2)) && (y_tilde(i) < quants(end - 1)))
indices = [indices; i];
end
end
x_filter = x(indices);
y_filter = y(indices);
[p,err] = polyfit(x_filter,y_filter,1);
y_fit = polyval(p,x_filter);
figure(3);
plot(x_filter, y_filter, x_filter, y_fit)
end
  2 件のコメント
Niya Bedzheva
Niya Bedzheva 2019 年 9 月 18 日
thank you very much, helpful as always!
another quick question: how can i plot the filtered data for a few variables (for example for a few drying_rates) in one graph?
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 18 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 18 日
Its my pleasure @Niya
Pass the input arguments y as a 1- D array (range of values), access y with proper indexing and plot accordingly

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by