フィルターのクリア

Store polyfit information of for loop in matrix

3 ビュー (過去 30 日間)
Jerry
Jerry 2022 年 4 月 12 日
回答済み: KSSV 2022 年 4 月 12 日
Hi, I have a graph with x = 6309x1 double and y = 6309x1 double.
I want to fit different increasing areas of the graph with polyfit: polyfit area 1-40; polyfit area 1-80; polyfit area 1-120; ........polyfit area 1-6280 (floor(length(x)/40)*40).
These are 157 (floor(length(x)/40)) different areas and I want to store the fitted y-Values in a 157x16280 (not used rows are gonna be replaced by zero)
How can I achieve this in a for loop? I tried the following, but it doesn't work and I cant fit 157 areas manually
yp = zeros(floor(length(xorg)/40)*40,1);
for i = 40:40:length(xorg)
for j = 1:floor(length(xorg)/40)
yp(:,j) = polyval((polyfit(xorg(1:i,1),yorg(1:i,1),9)), xorg(1:i,1));
end
end
  1 件のコメント
Jan
Jan 2022 年 4 月 12 日
Do you really want the output as 157x16280 or as 6280x157 matrix?

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

回答 (2 件)

Jan
Jan 2022 年 4 月 12 日
Maybe:
n = floor(length(xorg) / 40) * 40;
yp = zeros(n, 1);
for j = 1:floor(length(xorg)/40)
m = j * 40;
yp(:, j) = polyval(polyfit(xorg(1:m), yorg(1:m), 9), xorg(1:m, 1));
end

KSSV
KSSV 2022 年 4 月 12 日
You may save them into a cell as well.
yp = cell(floor(length(xorg)/40)*40,1);
for i = 40:40:length(xorg)
for j = 1:floor(length(xorg)/40)
yp{j} = polyval((polyfit(xorg(1:i,1),yorg(1:i,1),9)), xorg(1:i,1));
end
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by