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

7 Ansichten (letzte 30 Tage)
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 Kommentare
Chunru
Chunru am 23 Jul. 2021
Bearbeitet: Chunru am 23 Jul. 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 am 23 Jul. 2021
Bearbeitet: Image Analyst am 23 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 23 Jul. 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 Kommentare
Stephen
Stephen am 23 Jul. 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'

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Image Analyst
Image Analyst am 23 Jul. 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 am 23 Jul. 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);

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by