?? graph.m
字號:
function Graph(x,y,minx,maxx,weight,labelx,labely, heading, colourfit, colourxy, RSSI, PER, yes_fit)%This function ->% Graph: Creates a plot of datasets y vs x and% then proceeds to calculate the weigted line of best fit % using a linear polynomial and graphs the resulted fit% if asked with the colour argument as follows:% 'y' = yellow, 'm' = magenta, 'c' = cyan, 'r' = red, 'g' = green,% 'b' = blue, 'w' = white or 'k' = black% Function description is:%Graph(x data, y data, weights of data, x-axis label,% y-axis label,graph heading, the colour for the linear fit, % colour for the data, if RSSI is used, is PER is used % and if a fit is wanted in the created figure)fh = figure();iptsetpref('ImshowBorder','tight');legh_ = []; legt_ = {}; % handles and text for legendhold on;% --- Plot data originally in dataset "y vs. x"if(RSSI == 1) xy = plot(x, y, '.'); axis ([minx maxx 161 230]); set(xy,'Color',colourxy);else xy = plot(x, y, '.'); axis ([minx maxx min(y) max(y)]); set(xy,'Color',colourxy);end% --- Create fit fitopt = fitoptions('method','LinearLeastSquares','Weights',weight);set(fitopt,'Weight',weight);% Fit this model using new data where poly1 for a linear fit and poly'x' % for any (x + 1) order polynomialx = x(:);y = y(:);weight = weight(:);curvefit = fit(x,y,'poly1',fitopt)ci = confint(curvefit,0.95)if(yes_fit == 1) % Plot this fit wgt_ = plot(curvefit); axis ([minx maxx min(y) max(y)]); set(wgt_(1),'LineWidth',2,'Color',colourfit) % Add legend for line of Best fit legh_(end+1) = wgt_(1); %point used legt_{end+1} = 'Weighted Line of Best Fit'; %label legend(legh_, legt_); endhold off;%Labels for x,y and headingtitle(heading);xlabel(labelx); ylabel(labely);f_gcf = getframe(gcf); % get graphic contentimwrite(f_gcf.cdata,[heading '.jpeg']); %save content with heading as prefix
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -