gscatter3b.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function gscatter3b(x,y,z,group,clr,sym,siz,doleg,xnam,ynam,znam)
  2. %GSCATTER3B 3D Scatter plot with grouping variable
  3. % gscatter3(x,y,z,group,clr,sym,siz,doleg,xnam,ynam,znam)
  4. % Designed to work in the exactly same fashion as statistics toolbox's
  5. % gscatter. Differently from GSCATTER3, this function requires the
  6. % statistics toolbox installed.
  7. %
  8. %
  9. % See also GSCATTER, GSCATTER3
  10. %
  11. % Copyright 2017 Gustavo Ferraz Trinade.
  12. % Set number of groups
  13. cgroups = unique(group); %, 'stable');
  14. cmap = lines(size(cgroups,1));
  15. % Input variables
  16. if (nargin < 5), clr = lines(max(size(cgroups))); end
  17. if (nargin < 6) || isempty(sym), sym = '.'; end
  18. if (nargin < 7), siz = 20; end
  19. if (nargin < 8), doleg = 'on'; end
  20. if (nargin < 9), xnam = inputname(1); end
  21. if (nargin < 10), ynam = inputname(2); end
  22. if (nargin < 11), znam = inputname(3); end
  23. nargin
  24. % Get current axes
  25. a = gca;
  26. hold(a,'on')
  27. % call GSCATTER and capture output argument (handles to lines)
  28. h = gscatter(x, y, group,clr,sym,siz,doleg,xnam,ynam);
  29. legend('Interpreter', 'none')
  30. for i = 1:max(size(cgroups))
  31. if iscell(cgroups) || ischar(cgroups)
  32. gi = find(strcmp(group,cgroups(i)));
  33. else
  34. gi = find(group == cgroups(i));
  35. end
  36. set(h(i), 'ZData', z( gi ));
  37. end
  38. zlabel(a,znam);
  39. view(3)
  40. end