挑戰在於三維表面繪圖函數(網格,衝浪等)正在尋找z值的二維矩陣。所以要使用它們,你需要從數據中構建這樣一個矩陣。
當前數據是三維空間中點的海,所以您必須將這些點映射到曲面。一個簡單的方法是將X-Y(溫度 - 溼度)平面分成多個分箱,然後取所有Z(功率)數據的平均值。下面是一些使用accumarray()計算每個bin的平均值的示例代碼: %指定bin的大小 Tbin = 3; Hbin = 20;
% Create binned average array
% First create a two column array of bin indexes to use as subscripts
subs = [round(Havg/Hbin)+1, round(Tavg/Tbin)+1];
% Now create the Z (power) estimate as the average value in each bin
Pest = accumarray(subs,Pavg,[],@mean);
% And the corresponding X (temp) & Y (humidity) vectors
Tval = Tbin/2:Tbin:size(Pest,2)*Tbin;
Hval = Hbin/2:Hbin:size(Pest,1)*Hbin;
% And create the plot
figure(1)
surf(Tval, Hval, Pest)
xlabel('Temperature')
ylabel('Humidity')
zlabel('Power')
title('Simple binned average')
xlim([14 24])
ylim([40 80])
圖形有點粗(不能張貼照片呢,因爲我是新的),因爲我們只有幾個數據點。我們可以通過將其值設置爲NaN來刪除任何空箱來增強可視化。此外,裝箱方法隱藏了Z(功率)數據的任何變化,因此我們也可以使用plot3覆蓋單位點雲,而不繪製連接線。 (再一次B/C我是新無圖像)
的最後情節附加代碼: %%展開情節
% Remove zeros (useful with enough valid data)
%Pest(Pest == 0) = NaN;
% First the original points
figure(2)
plot3(Tavg, Havg, Pavg, '.')
hold on
% And now our estimate
% The use of 'FaceColor' 'Interp' uses colors that "bleed" down the face
% rather than only coloring the faces away from the origin
surfc(Tval, Hval, Pest, 'FaceColor', 'Interp')
% Make this plot semi-transparent to see the original dots anb back side
alpha(0.5)
xlabel('Temperature')
ylabel('Humidity')
zlabel('Power')
grid on
title('Nicer binned average')
xlim([14 24])
ylim([40 80])
我認爲plot3應該可以工作。 –
我嘗試過使用plot3,但我希望它處於表面或平面的形狀。比如這個形狀,例如:http://store2.up-00.com/Jun11/tVv30947.jpg我認爲這是使用網格,但我不知道如何。 – user488182