Can/How Do I Create a Custom Numeric Type

조회 수: 4(최근 30일)
James Mulhern
James Mulhern 2017년 11월 29일
답변: Walter Roberson 2017년 11월 29일
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
Rik
Rik 2017년 11월 29일
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?

댓글을 달려면 로그인하십시오.

답변(1개)

Walter Roberson
Walter Roberson 2017년 11월 29일
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().

범주

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