The Real Reason The Samurai Culture Went Extinct
The samurai were a group that mystifies modern onlookers in a way that few other cultures have. They are often characterized as a stoic warrior class, placing honor over all else in life as they served their Damiyō, or local lord. While in a relative sense this is true (executing commoners for even slight disrespect was "honorable" to the samurai), media depictions of their customs and demise paint a different picture from reality. For instance, a key component in the 2003 film "The Last Samurai" is that the samurai rebels in the film purposefully never use firearms because they are considered dishonorable.
This is in spite of the fact that feudal Japan had been introduced to matchlock muskets by the Portuguese in 1543. The former proceeded to make heavy use of them during both Toyotomi Hideyoshi's centralization of Japan and the subsequent 1593 invasion of Korea (via World History Encyclopedia). While Japanese firearms technology stagnated during the isolationist era, by the 19th century, factions in Japan readily made use of Western weapons. The point here is that the samurai did not disappear due to a tie to honorable combat, as armor, swords, and pole-arms were only used as a last resort by the 1850s. Instead, it was a series of attempts to preserve their political and social power that led to the samurai's demise.
The Samurai perished after dividing their loyalties
In 1853, the emperor was still a religious figurehead when Commodore Mathew Perry arrived in Japan. It was the shogun, Tokugawa Iemochi, who opted to end Japan's 300+-year policy of isolation after the American's demand that he do so. The treaty led the Chōshū and Satsuma clans to rebel in 1864, supporting the emperor's nominal opposition to the decision. In response to his rising unpopularity, the shogun attempted to secure at least some power for his clan by relinquishing authority. Upon learning that the emperor would leave him nothing for this act, Iemochi raised an army (via Ranker).
With British and French support for the emperor and shogun respectively, the Boshin War lasted two years before the latter was finally defeated. Vestiges of his army and French advisors (pictured above) attempted to create The Republic of Ezo on the northern island of Hokkaido. They pleaded with the emperor to spare this new government and their feudal way of life, but he refused and they too fell in 1869 (via ThoughtCo). The Samurai were officially ended by decree in 1876. Aside from a poorly armed rebellion by the now regretful Satsuma clan (who this time did use traditional weapons, but only because they didn't have much else), the Samurai would only survive in spirit through the new government's promotion of their Bushido moral code (via History.com).