Given that as already noted you will likely not initially be at all interested in such matters - there will (hopefully) be a time when you start to feel better, and as an adult man or woman in the 'sexually active age bracket' then you will for whatever reason need to relieve yourself. An old g\f told me that as a woman it much easier and can be performed more discretely - I can't agree or disagree but as I'm a man and will talk from a male perspective. Women do, and always will, and good luck to them - its an integral part of recovery and normality.
For a man it clearly involves having to diguise the eventual 'output' and also an accompanying acoustic moans and groans (women also take note!)...... This is easily achieved by use to the readily available tissues and waste bins and is always, always, best done at night after 'lights out'. I have never had a shared room - we were four to a 'bay' off the main ward corridor - so you could easily hear people coming along - but at night hardly ever did - and when they did, you just paused, later on I got so 'good' at it I never bothered to even pause.
You'll almost never be disturbed, can take as long as you wish and have a snooze afterwards - much better than sleeping pills! No one will ever know .... but if you are plugged into a heart monitor etc....caution - or you can just 'brass it' - call the night nurse, tell her your problem and simply state that you are going to have to masturbate and she is to thus ingonre the readings in the immediate future. This direct approach works and is appreciated, try it ! Either way she now knows where you are coming from .... a good 'chat up line' - no promises, but you now have friend who 'knows' you, as a direct honest (sexually mature) chap.
Should you have suffered from an accident that limits your hand movements then you do have an issue - now I have never been as unfortunate, but am assured (nurse friend) that if you are in this position 'arrangements can be made' for you to be (obviously unofficailly) relieved - wash time is the usual time for this to occur, but be aware it can also be performed during the night shift - when all hospital wards are virtually 'unmanned', the lights are out, no visitors (or g/fs or wives), no senior staff and no patients walking around - its easy.
So there you have it - not the final word on the issue, but my take on a fairly routine occurance, its no big issue. All the understandable rules are inplace to protect minors and 'vulnerable / immature patients' - and so they should be.
But for 'you and I' its back to work and normality asap, and masturbation IS an integral part of this and your hospital stay.
Good luck - I hope you never have to !