MATLAB Answers

0

Error using figure: First argument must be a figure object or a positive Integer

Asked by Jochem Bonarius on 7 Aug 2018
Latest activity Commented on by Jan
on 28 Jul 2019
temp = uint32(1);
figure(temp);
Gives:
Error using figure
First argument must be a figure object or a positive Integer
If anything, 'temp' is definitly a positive integer. What is wrong? (Fix it Mathworks...)

  4 Comments

Show 1 older comment
"But it would be insane if that was the correct solution: casting an integer to double in order to produce an integer...."
Not really. MATLAB's default class is double, and most internal processing uses double. Some operations only work with double, e.g. adding double scalars to arrays of any class or size. With MATLAB only use integer classes if your algorithm specifically require them. For this trivial code there is no memory or speed advantage to using integers types, so there is no real reason for you to complicate your code and use a non-default class for that value.
For no obvious reason you decided to make your code more complex than it needs to be. Why not just do this?:
temp = 1;
figure(temp);
It works perfectly.
@Stephen Cobeldick becasue the uint32 values come directly from a MySQL database (not mine to change). As a programmer it sounds insane that I have to recast these to double in order to get a 'mathematical integer' between 1 and 2^31-1. IMHO figure should just as well work with an int-type. I haven't encountered this using R, Python or Mathematica...
"I haven't encountered this using R, Python or Mathematica..."
Sure, because other languages have their own "features", e.g. Python's default of integer division, which was a much more significant "feature" that caused far more people problems than this "feature" of MATLAB's. Both are documented too!
Comparing "features" like this is likely to be an endless game that no one wins.
"IMHO figure should just as well work with an int-type."
I totally agree. You should make a feature request: click "My Service Requests" at the bottom of this page:

Sign in to comment.

Products


Release

R2018a

1 Answer

Answer by Pawel Jastrzebski on 7 Aug 2018
 Accepted Answer

The doc says the input argument must be of double type:

  15 Comments

Ah, yes, the driver only needs to know that becasue they /have/ to due to technology limitations... But actually, they would prefers not to! I mean, in the first cars you needed to oil the pistons and gears manually, and had to operate choke and even timing advancement manually.... But those days are long gone.vModern cars offer a lot a neat features like oil level warning (better then the idiot light) and wireless tire pressure sensors. If you would offer options on cars that you would never need to check oil level or tire pressure, people would gladly buy it!
Users don't want to be bothered with technicallities. They actually would like the computer to read their mind and do excactly what they want, without putting any effort into it.
But anyhow, let's agree to disagree...
One more thing
"% For plotting into a specific figure use:
FigH = figure;
plot(FigH, X, Y)"
Doesn't work. Just try it.
QED: so easy to get it wrong...It is just not user friendly.
Furthermore: if somebody closes the figure, it's handle disapears. If by accident, this could mean a script crashes. Could mean you lose a lot of simulation time. With the "figure(1);" method a new figure will just be opened... no crash...
@Jochem: You are right, the figure handle is not correct to define the parent of a plot command. Of course an axes is needed. This was a too sloppy translation of my own handle graphic objects, in which this call is valid. See my edited code. Thanks for checking this detail.
figure(1) will work. The original question concerned figure(uint32(1)). Then the actual problem was the error message, which can be misunderstood by a person, who is not familiar with the Matlab language.
Did you write an enhancement request, such that Matlab fixes the error message?

Sign in to comment.