2016-02-08 72 views
0

我正在使用此生成的代碼來繪製兩個向量之間的心理測量函數:不同的標記在MATLAB情節

smqi=[0 0.504500000000000 0.540500000000000 0.574800000000000 0.459400000000000 0.500800000000000 0.533900000000000 0.401700000000000 0.462100000000000 0.511300000000000 0.291300000000000 0.347300000000000 0.419900000000000 0.491700000000000 0.552400000000000 0.598600000000000 0.392600000000000 0.426000000000000 0.451400000000000 0.334900000000000 0.359500000000000 0.371300000000000 0 0.640800000000000 0.760600000000000 0.847100000000000 0.336200000000000 0.409200000000000 0.463000000000000 0.357600000000000 0.437700000000000 0.504400000000000 0.421200000000000 0.500200000000000 0.579800000000000 0.452700000000000 0.557200000000000 0.592200000000000 0.314800000000000 0.313800000000000 0.344800000000000 0.315500000000000 0.348300000000000 0.355400000000000 0 0.558100000000000 0.636700000000000 0.702900000000000 0.361500000000000 0.427100000000000 0.469100000000000 0.389700000000000 0.457700000000000 0.489800000000000 0.446800000000000 0.528700000000000 0.589200000000000 0.441500000000000 0.475300000000000 0.499600000000000 0.325500000000000 0.360700000000000 0.364200000000000 0.338400000000000 0.368200000000000 0.396200000000000 0 0.702500000000000 0.813100000000000 0.995500000000000 0.370600000000000 0.476800000000000 0.594300000000000 0.355200000000000 0.452000000000000 0.528500000000000 0.484000000000000 0.567400000000000 0.671500000000000 0.454000000000000 0.460700000000000 0.469600000000000 0.299900000000000 0.318300000000000 0.361900000000000 0.264800000000000 0.263000000000000 0.279500000000000]; 
MOS=[0.240085000000000 0.558541000000000 0.861963000000000 0.935125000000000 0.276903000000000 0.634308000000000 0.838878000000000 0.268853000000000 0.274772000000000 0.724518000000000 0.285545000000000 0.238901000000000 0.477684000000000 0.338700000000000 0.655736000000000 0.656328000000000 0.138511000000000 0.388422000000000 0.582929000000000 0.368178000000000 0.364626000000000 0.341423000000000 0.237362000000000 0.728069000000000 0.894282000000000 1 0.348526000000000 0.689712000000000 0.712087000000000 0.473541000000000 0.558778000000000 0.600331000000000 0.480052000000000 0.638688000000000 0.924944000000000 0.349947000000000 0.765834000000000 0.826684000000000 0.279507000000000 0.315852000000000 0.529892000000000 0.193678000000000 0.282112000000000 0.375873000000000 0.266012000000000 0.536285000000000 0.739079000000000 0.924825000000000 0.362969000000000 0.516160000000000 0.724162000000000 0.417663000000000 0.649461000000000 0.682846000000000 0.540784000000000 0.823606000000000 0.900438000000000 0.277850000000000 0.318693000000000 0.433763000000000 0.221617000000000 0.281165000000000 0.381674000000000 0.141352000000000 0.335740000000000 0.391263000000000 0 0.659879000000000 0.834853000000000 0.953475000000000 0.502664000000000 0.609921000000000 0.818042000000000 0.402155000000000 0.543270000000000 0.755890000000000 0.470700000000000 0.621996000000000 0.748905000000000 0.375873000000000 0.501243000000000 0.682254000000000 0.126080000000000 0.294779000000000 0.353972000000000 0.223748000000000 0.369599000000000 0.261276000000000]; 
function [fitresult, gof] = createFit(smqi, mos) 
%CREATEFIT(SMQI,MOS) 
% Create a fit. 
% 
% Data for 'untitled fit 1' fit: 
%  X Input : smqi 1x88 
%  Y Output: mos 1x88 
% Output: 
%  fitresult : a fit object representing the fit. 

[xData, yData] = prepareCurveData(smqi, mos); 

% Set up fittype and options. 
ft = fittype('erfc((a+b*x)/sqrt(2))/2', 'independent', 'x', 'dependent', 'y'); 
opts = fitoptions('Method', 'NonlinearLeastSquares'); 
opts.Algorithm = 'Levenberg-Marquardt'; 
opts.Display = 'Off'; 
opts.StartPoint = [0.83763959965349 0.463660782983039]; 

% Fit model to data. 
[fitresult, gof] = fit(xData, yData, ft, opts); 


% Plot fit with data. 
figure('Name', 'untitled fit 1'); 
h = plot(fitresult, xData, yData); 
legend(h, 'mos vs. smqi', 'untitled fit 1', 'Location', 'NorthEast'); 
% Label axes 
xlabel smqi 
ylabel mos 
grid on 

我要爲每個組的矢量SMQI和MOS而22個值的指定不同的標記物保留同一行(​​)。 我關注了分散函數,但我沒有成功解決這個問題。

幫助?

+0

請包括您的數據。 – thewaywewalk

+0

我的數據只是浮點值。我必須爲每個向量包含88個值? (代碼運行良好,但我只是想在每個子向量中放置標記) – Anass

+1

如果你給我們一些東西來玩,它就更有可能提供你的答案。我懶得想一個足夠的例子來重現你的情況。 – thewaywewalk

回答

0

最簡單的做法是將您的xDatayData變量重塑爲[X x 4],然後將這些變量傳遞給繪圖以爲每個組創建單獨的繪圖對象。然後您可以根據需要設置標記。

xData = reshape(xData, [], 4); 
yData = reshape(yData, [], 4); 

p = plot(xData, yData, '.'); 
set(p, {'Marker'}, {'.'; 'o'; 'x'; '*'}) 

hold on 
plot(fitresult); 
+0

感謝您的回覆,但解決方案中有超過4個標記。我想爲每個22值的標記,因爲我有88個值=>每個22值1標記。 – Anass

+0

已更新答案 – Suever

+0

但「fitresult」變量如何?你沒有把它放在劇情功能? – Anass