Matlab 自定義函式擬合

2021-06-10 08:51:54 字數 1728 閱讀 3928

%randomaccess j0237_2 reference

%basketballpass,bqsqare, blowingbubbles,racehorses,

close all;

clear all;

rd = [

1507.09 40.64

755.76  36.89

376.83  33.56

196.96  30.77

1610.73  37.97

631.13  34.63

284.29  31.81

141.13  29.12

1634.23  38.18

749.48  34.79

353.55  31.62

166.08  28.72

1193.66  39.44

587.38  35.73

288.11  32.34

144.13  29.56

];rd_s(1,1:4,1:2) = rd(1:4,:);

rd_s(2,1:4,1:2) = rd(5:8,:);

rd_s(3,1:4,1:2) = rd(9:12,:);

rd_s(4,1:4,1:2) = rd(13:16,:);

n = 4;

sample_number = 4;

colorset = ,,,};

for seq_id = 1:1:n

x = rd_s(seq_id,:,1); %rate

y = rd_s(seq_id,:,2); %distortion

%method 1

fx = inline('a(1)*(x.^2) + a(2)*sqrt(x) + a(3)','a','x');

a = nlinfit(x,y,fx,[1 1 1]);

x1 = min(x):20:max(x);

y1 = a(1)*(x1.^2) + a(2)*sqrt(x1) + a(3);

%method 2

fx2 = polyfit(x,y,2);

yvalue = polyval(fx2,x);

x2 = x1;

y2 = polyval(fx2,x2);

%y2 = fx(1)*x1.^2 + fx(2)*x1 + fx(3); %polyval(fx,x1);

plot(x,y,colorset,x1,y1,colorset);

hold on

plot(x2,y2,colorset);

grid on;

end% for seq_id = 1:1:n

%     x = rd_s(seq_id,:,1); %rate

%     y = rd_s(seq_id,:,2); %distortion

%     fx = polyfit(x,y,2);

%     yvalue = polyval(fx,x);

%     x1 = 0:20:max(x);

%     y1 = polyval(fx,x1);

%     %y2 = fx(1)*x1.^2 + fx(2)*x1 + fx(3); %polyval(fx,x1);

%     plot(x,y,colorset,x1,y1,colorset);

%     hold on

%     grid on;

% end

matlab學習 matlab自定義函式的編寫

判斷乙個數是否為素數 function p myprime a for i 2 a 1if 0 rem a,i p 0 break elseif i a 1 p 1 endend 測試 clc n input 請輸入乙個數 res myprime n if res 1disp 是素數 else di...

Matlab自定義初始化函式

有時候,有些輸出的初始化不能在模型中直接設定,這時候可以通過設定模型引數配置。開啟 configuration parameters code generation custom code 選項卡,在右側的上半部分 insert custom c code in generated 選項卡裡選擇 i...

MATLAB學習 函式自定義與呼叫

另乙個部落格位址 konosuba.xyz matlab可以在單獨的.m檔案中定義函式 比如有一檔案myadd.m,檔案中內容為 function y myadd a,b 這裡可以寫函式的使用說明,前面以 開頭 在工作區中,help myadd將顯示此處的說明 y a b end 可以略去第一行fu...