2
$\begingroup$

I am new to Matlab and data visualization in general. I am plotting an A vs. B relation based on 100 values of (A,B) using plot(A,B) which gives me a nice 2-D line plot. Now I want to run 1,000 trials of this and see how the A vs. B relation varies across the trials. (A has a random component and B is dependent on A so the trials will yield different results.)

What is the best way in matlab to visualize/analyze this? (I presume drawing 1,000 2-D line plots and looking at them isn't an option.)

$\endgroup$
2
  • $\begingroup$ I really don't know matlab, so I'll have to let someone else answer, but from your description it seems like you could plot r-score by iteration & accomplish your goals. In general, 3 variables can be explored w/ scatterplot matrices, coplots, and interactive 3D plots. I discussed related issues in an answer here: stats.stackexchange.com/questions/21809/… hope that helps. $\endgroup$ Commented Feb 22, 2012 at 22:42
  • 3
    $\begingroup$ The master question here is what do you want to show with this visualization. $\endgroup$
    – user88
    Commented Feb 22, 2012 at 23:29

1 Answer 1

1
$\begingroup$

I attached some code that might help get you started. (I am essentially treating your example as being equivalent to displaying confidence intervals around a curve)

X = linspace(0, 2*pi, 100);
X = X';
Y = sin(X);
%scatter(X,Y, '.')

Noise = randn(100, 1000);
data = bsxfun(@plus, Y, Noise);

% Calculate mean and standard deviation
meanData = mean(data, 2);
stdData = std(data, 0, 2);

%%

figure;

% Create multiples of standard deviation
stdevRange = 0.5:0.5:4;
numColormap = length(stdevRange);

% The patch colors will be shades of red
cm = [linspace(1, .97, numColormap);
    linspace(.3, .97, numColormap);
    linspace(.3, .97, numColormap)]';
set(gcf, 'Colormap', cm);
caxis(gca, stdevRange([1 end]));

% Create patch data along with corresponding colors
colorscale = numColormap:-1:1;
pY = arrayfun(@(z) [meanData-z*stdData;flipud(meanData+z*stdData)], fliplr(stdevRange), 'UniformOutput', false);
pY = [pY{:}];
cD = arrayfun(@(z) z*ones(length(X)*2, 1), colorscale, 'UniformOutput', false);
cD = [cD{:}];

% Create confidence bound patches
hCBPatch = patch(repmat([X; flipud(X)], 1, length(stdevRange)), ...
    pY, cD, 'FaceColor', 'flat', 'CDataMapping', 'direct', ...
    'EdgeColor', 'none');

% Plot mean data
line(X, meanData);

% Create colorbar with appropriate labels
stp = range(stdevRange)/(numel(stdevRange)*2);
hColorbar = colorbar;
ytick = stdevRange(1)+stp:stp*2:stdevRange(end)-stp;
yticklabels = cellstr(num2str(stdevRange', '%-g'));
yticklabels{end} = [yticklabels{end}, '+'];
set(hColorbar, 'YTick', ytick, 'YTickLabel', yticklabels);

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.