Matlab Crashes When Executing randperm Function

I am running Matlab 2013b.
I have a function that analyzes data. It runs correctly when executed within Jenkins running on Linux. The code takes about an hour to run.
When I run on my Windows PC in a Putty window connected to a Linux box Matlab crashes every time. It crashes when executing the line "var = randperm(N)", where N is a double with a value = 58. I stepped through the code manually and stopped at different points and typed "var = randperm(58)" without any problem. This problem was verified by a second engineer who had run across the same problem weeks before me.
I have no idea how to troubleshoot this problem.
Thanks in advance for any help.
Mike

댓글 수: 9

Maybe it is worth trying to use round(). It looks like N is computed somewhere inside your code, e.g.
randperm(round(56.00001))
ans = 1x56
19 5 35 18 55 28 22 46 32 42 23 45 49 24 4 37 33 52 16 25 11 2 10 38 31 17 21 34 6 8
Hi Sulaymon,
I tried your suggestion but the problem remains. Also, I tried directly passing non-integer values of N into randperm to see how randperm would handle it. randperm performs error checking on the input arguments.
Thank you for the suggestion.
Hi Sulaymon,
I assume that you are checking the value of N when it crashes on that line (using the debugger although rhere are other ways to accomplish it) and not merely typing
var = randperm(58)
at various spots. If N truly equals 58 it's hard to see how this couId occur. You might also try your own version
function a = randperm1(n)
[~,a] = sort(rand(1,n)); % row vector
end
just to see what happens.
David,
"I assume that you are checking the value of N when it crashes on that line"?
Yes. The actual code is
idx = randperm(length(X))
where X is an 1xN double array, and N is always <= 6000.
I stopped at the troublesome line in the debugger and checked that the value was an integer. I even tried stopping at that line and typing in the command window
idx = randperm(2)
and Matlab crashed.
I like your idea of creating a different function and calling that - I hadn't thought of that. I wilI try it. I did however try changing the code to
NX = length(X);
idx = datasample(X,NX,'replace','false');
and it still crashes.
Thanks for the suggestion. I'll post my results.
Maybe check to make sure that
idx = 1:length(X);
works fine?
What shows up for
which -all randperm
It doesn't look to be involved here, but unless a person is 100% sure that x is a row or column vector, some people tend to stay away from the length(x) command, using size(x,n) instead because there is no question of one's intent. The length command gives the max size of x along any of its dimensions, which has been known to lead to unwanted surprises.
Jeff, the following works fine
idx = 1:length(X);
Walter,
which -all randperm
yields the following
built-in (/apps/MATLAB/R2013b/toolbox/matlab/randfun/randperm)
/apps/MATLAB/R2013b/toolbox/matlab/randfun/@RandStream/randperm.mexa64 % RandStream method
/apps/MATLAB/R2013b/toolbox/matlab/randfun/@RandStream/randperm.m % RandStream method
David,
I agree with your use of size over length, but, this is code that has been developed over years that I am now making changes to. I always tread lightly when I am the new guy.
Thank you all for your time.
Torsten
Torsten 2024년 2월 23일
편집: Torsten 2024년 2월 23일
I don't know if this could be the reason, but I had a similar problem with "octave" under Windows 11.
Switching the default console to the “Windows Console Host” solved the problem:
But since you work under MATLAB 2013, you might have to have a much lower Windows version installed.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

제품

릴리스

R2013b

질문:

2024년 2월 17일

편집:

2024년 2월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by