當前位置:編程學習大全網 - 電腦編程 - matlab編程問題。求壹維數組差值最小兩個數的平均值

matlab編程問題。求壹維數組差值最小兩個數的平均值

代碼如下,用了24個隨機數,可以換成自己的數據,不影響:

clear all;

clc;

rand('seed',0);

a=rand(1,24);

a=sort(a);

for j=1:1:24-7

b=[];

for i=1:24-j

b(i)=a(i+1)-a(i);

end

c=find(b==min(b));

a=[a(1:c-1) (a(c)+a(c+1))/2 a(c+2:end)];

end

-----------運行結果

a = 0.0405 0.2190 0.4001 0.5564 0.6655 0.8386 0.9326

  • 上一篇:昆明導航藝術培訓學校怎麽樣
  • 下一篇:桑塔納電子助力沈從哪裏調節?
  • copyright 2024編程學習大全網