Loren on the Art of MATLAB

Turn ideas into MATLAB

New Datatype under Development for Possible MATLAB Release 15

Posted by Loren Shure,

There is a new datatype we are playing around with that we hope to make available in an upcoming release and we would like your input beforehand.


New Datatype in Action

Let me show you the new datatype in action so you can first get a feel for it.

inputData = magic(3)
inputData =
     8     1     6
     3     5     7
     4     9     2
outputValues = dis(inputData);

Let's Examine the Output

Why are you asking?
     4     2     3
     1     9     6
     8     7     5

Well, that's a bit strange, isn't it? I wonder what the relationship between inputData and outputValues is. What can we learn about outputValues?

whos outputValues
  Name              Size            Bytes  Class    Attributes

  outputValues      1x1               248  dis                

Well, it's a dis array. Let's look at it again.

What's it matter to you?
     5     6     9
     4     3     2
     7     8     1

Say what? Let's check it a few more times.

Who wants to know?
     6     3     9
     5     8     7
     4     2     1
Who wants to know?
     5     2     9
     1     4     8
     7     6     3
Who are you to ask me that?
     5     3     7
     9     8     2
     1     4     6

Hoping you get the double meaning here - the dis array not only mixes up the values of the input for display purposes, but also tries to gently *dis*respect you along the way.

Even though this is a silly class, I'll show you the code so you can see how simple it is to make such a class.

type dis
classdef dis
    %dis dis is a class.
    %   In fact, it's a declasse class.
    properties (Access=protected)
    properties (Constant)
        Answers = {'Why are you asking?' ,...
            'What''s it matter to you?',...
            'Who are you to ask me that?',...
            'Who wants to know?',...
            'What''s the big deal?'}
        function display(obj)
            obj.Data(:) = obj.Data(randperm(numel(obj.Data)));
        function obj = dis(in)
            obj.Original = in;
            obj.Data = reshape(in(randperm(numel(in))),size(in));

Should We Invest More Resources?

Of course, I could also add some numeric functions like plus to dis, but I didn't take the time, in case you didn't find this possible new MATLAB addition useful. So please share your thoughts with us here.

Get the MATLAB code

Published with MATLAB® R2013a

3 views (last 30 days)  | |


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.