Message Boards Message Boards

GROUPS:

Adding nothing to a graph in case of false condition?

Posted 2 months ago
591 Views
|
4 Replies
|
0 Total Likes
|

Sketch of what I am trying to do:

I have a base graphic. If a certain part of a calculation found a result, I want to add another "piece" to that graphic. If no result was found, I don't want to add that piece.

So I'd like to write code like this:

Show[
       base graphic,
       If[result_found, piece,(* else *) NullGraphic]
    ]

So if result_found is True, it behaves as

Show [
      base graphic,
      piece
    ]

and if result_found is False, it behaves as

Show[
      base graphic
    ]

So the question is: Is there anything I can use where I wrote "GraphicNull" above? I already tried "Null" ... doesn't work.

Thanks ....

4 Replies
Posted 2 months ago

DuuuuH. Just solved it myself.

Show[
{
    baseobject,
    If[result_found,piece,Nothing]
}
]

Yes, Mathematica, has Null, Nothing, and None .... and they are all different. :)

You can also use {}.

Posted 2 months ago

Graphics[] works as well

Show[
    basegraphic,
    If[resultOK, piece, Graphics[]]
 ]

From the documentation for Graphics:

Graphics[] gives an empty graphic with the default image size.

Posted 2 months ago

Thanks so much for the help. Graphics[] is exactly what I was looking for. And of course you are right ... it says so in the documentation ... The moral is the old story "Read the documentation!"

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract