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

6 次查看(过去 30 天)
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 个评论
Chunru
Chunru 2021-7-23
编辑:Chunru 2021-7-23
Try "which newfunction" after error occurs and identify what the "newfunction" is. It is the "newfunction" that gives the trouble.
Image Analyst
Image Analyst 2021-7-23
编辑:Image Analyst 2021-7-23
@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.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2021-7-23
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 个)

Image Analyst
Image Analyst 2021-7-23
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 2021-7-23
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);

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by