Matlab_10

Another Function

OK - you should be getting the hang of this now! Just copying and pasting these examples in to Matlab and running them won't help so make sure you know what each line does, use the help system to look up the function names, and make some changes to the code. Here is how you use the new function:

>> clear all;
>> load matlab_08;
>> error_range_graph(m_08');
>> fancy_export([],'jpeg', 'myErrorGraph');

and here is the function code. When you have run it try changing the code so that the error bars in the first two graphs represent the standard error (SE).

function return_value = error_range_graph(any_data)
    %
    % ---
    % return_value = error_range_graph(any_data)
    %
    %   exploring errors and range plots
    %   part of a suite of short examples
    %   developed as part of Matlab tuition
    %   at Plymouth University by m coath
    % ---
    %

    D = any_data;

    % we need to know the number of columns in the data
    % for some calculations later

    nCols = size(D,2);
    X = 1:nCols;

    % This is for limiting the number of points 
    % to 20 if we need to

    X_Step = floor(nCols/20);
    reducedData = D(:, 1:X_Step:end);

    % plot mean and symmetrical error bars at 2*SD

    subplot(2,2,1);
    Y = mean(D);
    E = std(Y)*ones(size(X));
    errorbar(X,Y,E);
    axis tight;

    % plot mean and symmetrical error bars at 2*SD
    % by a different method

    subplot(2,2,2);
    upBarY = Y+E;
    downBarY = Y-E;
    polygonY = [upBarY fliplr(downBarY)];
    polygonX = [X fliplr(X)];
    patch(polygonX, polygonY, [.9 .8 .8], 'linestyle', 'none'); hold on;
    plot(X,Y);
    % there are too many points on the boxplot then use 20
    subplot(2,2,[3 4]);
    boxplot(reducedData, 'notch', 'on');
    return_value = 0;
end