Czech Lukas Rosol upset Nadal in the second round of Wimbledon last week. Nadal had planned to play an exhibition match against top-ranked Djokovic at Real's home stadium on July 14.
"I wish to apologize to all, especially the supporters who had already purchased tickets for this good cause," said Nadal, who won gold at the Beijing Olympics, in a statement on the Real Madrid website.
"Doctors have been examining my knee and say I suffer from tendinitis on the patellar ligament and that I must rest for 15 days, which prevents me from playing against Novak Djokovic as planned and announced."
Nadal made it clear that he is focused on the Olympics.
"I saw the doctors on Monday and began the recovery process to be fit to represent Spain in the London Olympics. We will try to look for a new date for the event.
"I will now combine my recovery with short holidays before returning to training in 15 days. Once again, thanks to all."
The event, organized by the Real Madrid and Rafa Nadal Foundations, had hoped to set a record attendance for a tennis match.
Nadal and Djokovic are expected to carry Spain and Serbia's flags at the Olympic opening ceremony in London on July 27.