Matlab says, I reached the max limit of recursion: " Maximum recursion limit of 500 reached. "

7 vues (au cours des 30 derniers jours)
Here's my code from Help Manual:
x = randn(100,1);
y = randn(100,1);
Xedges = [-Inf -2:0.4:2 Inf];
Yedges = [-Inf -2:0.4:2 Inf];
h = Histogram2(x,y,Xedges,Yedges)
Apparently there's some other conditions that need to be established before I can run this example code from Help manual, but being new to Matlab, I can' figure this out.
Appreciate any help you can provide.
Thanks,
Stephen
  3 commentaires
Chunru
Chunru le 23 Juil 2021
Modifié(e) : Chunru le 23 Juil 2021
Try "which newfunction" after error occurs and identify what the "newfunction" is. It is the "newfunction" that gives the trouble.
Image Analyst
Image Analyst le 23 Juil 2021
Modifié(e) : Image Analyst le 23 Juil 2021
@Chunru, like I said in my second answer below, if newfunction is the name of his m-file, there may be only one, but it's being called recursively. Fixes are in my answer below.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 23 Juil 2021
newfunction()
x = randn(100,1);
y = randn(100,1);
Xedges = [-Inf -2:0.4:2 Inf];
Yedges = [-Inf -2:0.4:2 Inf];
h = histogram2(x,y,Xedges,Yedges)
So, that's the full code? Your m-file is not by any chance called "newfunction.m" is it? Because the first line of newfunction would call itself recursively, like I tried explain to you in my first answer. To fix, either comment out that first line,
% newfunction()
x = randn(100,1);
y = randn(100,1);
Xedges = [-Inf -2:0.4:2 Inf];
Yedges = [-Inf -2:0.4:2 Inf];
h = histogram2(x,y,Xedges,Yedges)
or put the function keyword in front of it
function newfunction()
x = randn(100,1);
y = randn(100,1);
Xedges = [-Inf -2:0.4:2 Inf];
Yedges = [-Inf -2:0.4:2 Inf];
h = histogram2(x,y,Xedges,Yedges)
  2 commentaires
Stephen
Stephen le 23 Juil 2021
Thank you, that fixed it!
As the Chinese proverb goes, 'ask the question and appear foolish for a day, than not ask and remain a fool for life'
Image Analyst
Image Analyst le 23 Juil 2021
You're welcome. Thanks for accepting the answer.

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 23 Juil 2021
Once I changed Histogram2 to histogram2 (MATLAB is case sensitive), it works fine:
x = randn(100,1);
y = randn(100,1);
Xedges = [-Inf -2:0.4:2 Inf];
Yedges = [-Inf -2:0.4:2 Inf];
h = histogram2(x,y,Xedges,Yedges)
I suspect that your m-file is called Histogram2.m and that it's calling itself. It recurses deeper and deeper with no way to back out, until it eventually calls itself 500 times and throws that error you saw.
Correct the name to histogram2, and change the name of your m-file to something like test_histogram.m instead of Histogram2.m.

Chunru
Chunru le 23 Juil 2021
Try "clear all" before running the code. Change "Histogram2" to "histogram2" (case sensitive). It seems there is no recursive function in the code. If the problem cannot be resolved, do "dbstop error" before running the code and observe the error message.
x = randn(100,1);
y = randn(100,1);
Xedges = [-Inf -2:0.4:2 Inf];
Yedges = [-Inf -2:0.4:2 Inf];
h = histogram2(x,y,Xedges,Yedges);

Produits


Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by