Did the militaries of the medieval period have a defined unit structure like with modern militaries where you had six soldiers in a squad, three squads in a patrol, etc., Or were they more like 'grab a bunch of dudes and go that way'?
I can provide an answer from the South Asian perspective. We can look at several military systems that existed in the region in the medieval period. Let's start with the Rajputs, then we can also cover the Mughals.
RAJPUT MILITARY SYSTEM :
By the 13th century, the Rajputs were well entrenched into a feudal system of civil and military organisation. The land of a kingdom was divided into villages headed by rais, who were themselves subordinated to either individually or in groupings known as thikana to thakurs which initially was a term which referred to Rajputs or Kshatriyas exclusively, but eventually became a title and was used by Brahmins of the same feudal rank. Next were Samantas special ministers appointed by kings to administer a number thikanas or to serve in special roles in the administration. There were also a number of other feudal lords and chiefs, subordinated to the Raja, and several Rajas would be further subordinated to a Maharaja or a Great King.
The army itself was raised out of 6 military labour pools namely :
Maula or hereditary troops
Bhrita or regular forces/mercenaries
Sreni or troops supplied by guilds, towns etc.
Mitra or Suhrd or forces of allied states
Dwisad or Ari or soldiers alienated from the enemy camp, by bribery, or recruited after defeating the enemy
Atavika forces raised out of tribal groups such as Bhils
Among these groups the most important pool of military labour is Maula. This refers to those soldiers whose previous generations have owed loyalty to and have shown exceptional service towards the king, who in recognition of these services appoints them as part of his Maula troops. These troops were also often drawn from close and distant family members. For example, a king might have many brothers, who might have many sons and those sons might have married into families and those families might have several capable men of fighting age as well. The king would appoint men from this labour pool into his Maula force as he saw fit and each soldier would be replaced by a brother or son when they died. Hence making them hereditary troops both in terms of their replenishment and the fact that each successive generation inherited these troops. These men, being close friends and family of the king, meant they could be given independent charge, could advise him in war and could be appointed as commanders of any number of units.
Units were organised into 5, 30, 100, 1000 and 10,000. There did exist a corps of high teir officers to look after the management of the logistics, law and order and command of the entire army. Armies until the 11th century were composed of elephants, infantry and cavalry.
MUGHAL MILITARY SYSTEM
The Mughals inherited two military systems. The first from their Timurid Steppe heritage which meant that they relied and made use of large cavalry formations, where the majority were lightly armoured horse archers along with a smaller but equally important contingent of heavily armoured lancers. But by the time Babur made his foray or expedition into the subcontinent, he had adopted the Ottoman tactics of employing the Tabur Cengi or camp battle which basically improvised on the Hussite tactic of a wagon fort and blended the Steppe elements of light and heavy cavalry on the wings, therfore creating a centre of wagons, chained together, with missile units and artillery and melee infantry behind them, while also horse archers and heavy landers on the wings to enable the Mughal to employ their tulughma or encirclement maneuvers.
The army was organized along Timurid lines which meant that units were organised into 10,50,100,500,1000. Also larger units of 5000 and 10,000, could also exist.
Commanders and officers were always nobles, who during the reign of Babur were those loyal nobles who had followed him from Ferghana to Kabul and in later decades, under the reign of his successor Akbar,, were recruited from the pre-existing nobility of the subcontinent as well as other pools of manpower, by employing the Mansabdari system by which each noble had a rank, consisting of zat and sawar, indicating his rank in court and his stipulated number of troops. More often than not, the payment of the nobility which was the de facto administration and military officer corps of the Empire was not done through cash but rather assigning land which would yield the required revenue owed to the noble.
Another formation which was introduced by that could be interpreted as elite, were the Ahadis. The Ahadis were individual, aspiring officers who did not have the means to raise their own troops in order to warrant an Imperial mansab or rank ( a Mansab was the rank assigned to all nobles and officers of the Empire, it implied their payroll and troop quota), but still showed potential for leadership and command. These men were recruited by the Emperor since the days of Akbar himself, and were assigned the command of small units in the logistics, artillery, engineer or cavalry or infantry branches of the army. While its unclear whether or not these officers underwent regular rotation in order to become well rounded professionals or were kept in permanent employment into a specific branch in order to create specialised officers for each branch, it's certain that they were a corps of competent officers nonetheless. The Ahadis were also organised into cavalry formations, as columns of cavalry meant to accompany the Emperors at all times and to serve as reserve cavalry on the battlefield and to serve as an emergency reserve to meet unforeseen crisis.
CONCLUSION
Medieval military systems did have organisation and structure, with varying levels of complexity and sophistication, which depended on the resources at a state's disposal, the level of sophistication of it's administrative and organisational capabilities, the military cultures that the state comes into contact with and the ability of the state to adapt and innovate.
How similar these system were to modern militairies and their organisational structures? Well, apart from purely troop composition into various tiers of the organisational structure, not much.
It's a broad question and one that doesn't lend itself to an easy answer, which means the overall answer is "No", but a detailed "No" for the type of army being covered. I will answer here mostly for England as I am more familiar with it.
Generally, standing armies or organizations had a little bit more standardization in terms of units. So, a castle guard unit would likely have a certain number of what we would call NCO's and an overall officer responsible for the unit. There was no set size or structure beyond that. There could be a dozen men reporting to a single corporal, or it could be 4 men. In 1266, Reginald de Grey held Nottingham with 2 knights, their troopers, 20 mounted crossbowmen, a captain, 10 foot bowmen, and 20 archers. How much granularity and organization there was there is hard to say. The don't list any NCO positions, but it's a reasonable guess that there was some subdivision. This was a paid group for a specific period of time as opposed to a feudal levy, so that lent itself to round numbers. We don't know how many troopers were with the knights. That could be 2 troopers per knight or 5 or one knight could have 5 and the other 3. There was a great degree of latitude there.
But, my point is that longer period soldiers tended to have time to work out a greater degree of organization than a levy. The organization for Nottingham was likely not the same organization as another castle. The basic form would likely be the same, but the numbers could vary widely and whether they were expected to just hold the castle, or actively patrol. The Nottingham list above looks to be a patrol oriented organization. The mounted would do patrols and the captain and the foot crossbowmen and archers would hold the castle. (It took surprisingly few archers and crossbowmen to hold a castle).
The cavalry was more of a mess. They had to be raised by feudal levy. Each banneret owed the crown a certain number of knights and troopers based upon their wealth. These were called up for a certain number of days and the banneret was responsible for the pay and provisions for those days. Any kept after their term of levy had to be supported under the Crown's purse. So, a major magnate might owe hundreds of knights in service and each knight would have roughly 3-5 troopers in addition to the knight. A banneret could instead substitute money for actual forces of the crown agreed and it was generally in the crown's interest to do so for any forces not located nearby, then they would use that money to keep the ones he did have in the field for longer periods. The crown could also pay for mercenaries and that was also another longer standing organization that tended to be a little more structured.
The banneret was the only level of organization we have for this type of levy. The banneret was the person whose banner was responsible for the feudal obligation to the crown. It would be an earl with hundreds under his command. It could be a small titleholder with only himself and a couple troopers. There doesn't seem to be any subordinate structure below banneret across the levy. A banneret could have 1 knight and 5 troopers grouped under one banner. Or, it could be an Earl with 33 knights and 55 troopers. They would throw a number of bannerets together under a wing commander, or an overall commander, but the unit sizes would not be changed or altered and how each banneret handled distributing orders looks to have been very much a personal preference to the banneret.
I recommend The Welsh Wars of Edward I by John Morris. It goes into exhaustive details about the raising of an army in the 13th Century.