Can/How Do I Create a Custom Numeric Type

4 views (last 30 days)
James Mulhern
James Mulhern on 29 Nov 2017
Answered: Walter Roberson on 29 Nov 2017
I have an array that I am using to store the output data for my project. I initialize it using NaN and then overwrite the data as I calculate different parameters, however in some columns not every row is overwritten because some things are not calculated. I would like to create a custom numeric type that I can use to initialize the array instead of using NaN. NaN works, but it indicated that the cell had a calculation performed. I would like to create an numeric type that is like "Blank" or "No-Calc" or something, this way it is clear to an end user that that cell was not calculated.
Is this possible to do?
I think it could be done by making it a cell array, however it would become tedious to be constantly converting to and from a cell.
This is essentially what my data looks like
[1, 2, 3]
[1, 2, NaN]
[1, 2, 3]
This is what I want
[1, 2, 3]
[1, 2, Blank]
[1, 2, 3]
I also do not want to use 0 because it the cells could actually be equal to zero. Maybe Inf or -Inf would be better. Anyway please let me know if I can create a custom numeric type, and if so how to do it. Thanks
  2 Comments
Rik
Rik on 29 Nov 2017
So your main objection is that it isn't clear to an end-user what NaN means in this context? Because then this seems like killing mosquitos with nukes. Isn't it easier to explain what NaN means in comments or in a GUI?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 29 Nov 2017
I suspect that all you need to override is the display routine -- though I would also be concerned about what happened with fprintf() and sprintf().

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by