matlab parfor with arrayfun (sliced variable) - matlab

As the title says, I want to have a parfor loop with inside usage of arrayfun.
I created a minimal working example for the problem:
Having the following lines in a file called thisparfortest.m
function test=thisparfortest(countmax)
parfor count=1:countmax
test(count).nummer=count;
test(count).bisdrei=arrayfun(#(testnum)eq(test(count).nummer,testnum),1:3);
end
the command mcc('-e','-v','thisparfortest') results in
Compiler version: 4.18.1 (R2013a)
Error: File: **************\thisparfortest.m Line: 3 Column: 5
The variable test in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
Processing C:\Program Files\MATLAB\R2013a\toolbox\matlab\mcc.enc
Processing include files...
2 item(s) added.
Processing directories installed with MCR...
The file mccExcludedFiles.log contains a list of functions excluded from the CTF archive.
0 item(s) added.
Generating MATLAB path for the compiled application...
Created 43 path items.
Parsing file "****************\thisparfortest.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2013a\toolbox\compiler\deploy\deployprint.m"
(Referenced from: "Compiler Command Line").
Parsing file "C:\Program Files\MATLAB\R2013a\toolbox\compiler\deploy\printdlg.m"
(Referenced from: "Compiler Command Line").
Unable to determine function name or input/output argument count for function
in MATLAB file "thisparfortest".
Please use MLINT to determine if this file contains errors.
Error using mcc
Error executing mcc, return status = 1 (0x1).
but as advised mlint thisparfortest (and also checkcode) returns no problems - like in the editor.
The loop can be done and compiled as a for loop.
Please do not ask for the sense of these commands - they are just here for the mwe.
I think, this should be reported to mathworks - or have I done something wrong?
Some additions:
When running
function retval=thisparfortest(countmax)
helpfun=#(x)arrayfun(#(testnum)eq(x,testnum),1:3);
parfor count=1:countmax
retval(count).nummer=count^2;
retval(count).bisdrei=helpfun(retval(count).nummer);
end
with only the for loop it works, but when using the shown version with parfor it results in
Error using thisparfortest>(parfor supply) (line 3)
Undefined function or variable "retval".
Error in thisparfortest (line 3)
parfor count=1:countmax
Caused by:
Undefined function or variable "retval"
Shouldn't that be caught by mlint/checkcode? This happens without compiler.

I don't believe the issue has anything to with compilation. When I attempt to run your code in regular MATLAB I get the same error that the variable test in a parfor cannot be classified.
There's no bug here - not every piece of code can be run inside a parfor loop, and it's not possible for MATLAB to perfectly determine prior to runtime which pieces can and can't. It tries to do a good job, and when it does, the Code Analyzer will tell you prior to runtime - but when it can't, it will give a runtime error as you've found.
Perhaps you can think of a way that MATLAB could have statically determined that this variable could not be classified - in that case this could be reported to MathWorks as an enhancement request to Code Analyzer.

Related

How to locate where a built-in function is defined?

In MATLAB, there are roughly 3 ways to define functions: non-comment-only .m files, .p files, and compiled code (e.g. DLL, MEX).
Knowing where a function is defined could be helpful in several cases, such as when a breaking change was introduced to some function outside our control, and we'd like to try to revert to an old version in the hopes of getting our code working again; or when trying to reverse-engineering some undisclosed algorithm.
The which function is usually very good at identifying function definitions and their locations (which works for .m, .p and MEX), but isn't very useful when it comes to shared library functions, where (at best) it points to a comment-only documentation file:
>> which _mcheck
built-in (undocumented)
>> which svd
built-in (D:\Program Files\MATLAB\R2019a\toolbox\matlab\matfun\svd)
If so, assuming a function found within a shared library is called during the execution of my code, how can I locate the specific file (DLL) that contains it?
It turns out that dbstop can be used for this. For example:
>> which svd
built-in (D:\Program Files\MATLAB\R2019a\toolbox\matlab\matfun\svd)
>> dbstop svd
Warning: Entering debug mode is only supported within running MATLAB code files.
Warning: MATLAB debugger can only stop in MATLAB code files, and "libmwmathlinalg>svd" is not a MATLAB code file.
Instead, the debugger will stop at the point right before "libmwmathlinalg>svd" is called.
From there's it's just a matter of finding a file called libmwmathlinalg (with the relevant extension) - which isn't a difficult task if your drive is indexed.

Two bag-of-words classifiers, Matlab

I'm trying to implement "Two bag-of-words classifiers", so I found resources at this website. http://people.csail.mit.edu/fergus/iccv2005/bagwords.html This website provides complete files including Matlab code. But I've encountered some errors while implementing the code.
I run this code on Matlab 2011b , under Windows 7.
At first, some errors occur because of path experession, but this can be soleved. At file "gg_lola_km_binary.m", replace "/" with "\" due to path expression in Windows, and it also needs to allocate appropiate path. After doing this, this error has been solved, but the next error occur:
Error using imformats>find_in_registry (line 512)
Format specifier must be a 1-D character array.
I consider whether this error results from Matlab version difference, but I don't know how to solve this problem.
Thank You
The error should be something to do with the format of your Input.Not your Matlab version. Most of the written distributed functions are constructed using basic operations and should work on most versions of Matlab (even the older versions); if not it will probably prompt an unknown function being called which it does not recognize.
Your errors seems to say that:
The function imformats>find_in_registry is looking for a 1 dimensional character array, which it did not find. (most possibly in your input file format or file path). I suggest you check again, without further information, we cannot help you.

Error in Compiled exe, but running in m file MATLAB

I have build a program that run properly in m file MATLAB. but when I compile to exe using Matlab compiler, some function didn't work. here is the error command window show on matlab execute program
undefined function or method 'maple' for input arguments of type 'char'
error in ==> function_a at 5
codes on function_a.m is
function function_a(msg)
format long
%parameter p & q
maple('z1:=',randint(1,1,[12 20])); %these run in m.file, but not in exe compile
p=maple('nextprime(z1)');
p=str2double(p);
is there any solution for that?please need your advice, many thanks
Assuming you have tried to compile the version from exactly this sourcecode and that you call it twice with exactly the same input, it appears that MATLAB simply does not realize that the function maple will be used by you.
I have had this before with some project, eventually I decided to use the 'add additional resource to project' option in deploytool.
Depending on your needs you can either just add the function, or the folder containing this function.
The command maple is from Symbolic Toolbox, which is not supported by MATLAB Compiler. You will not be able to successfully compile and run your program.
What's happened is that the maple command is not allowed to be compiled, so when the .exe runs, it can't find the function maple, and gives you the error you're seeing. It would be nice if MATLAB gave you a more informative error message, but it seems it doesn't.

How do I use the lteRMCDL tool?

I'm following an example from MathWorks.
When I run the code I get an erroneous output
Error in Untitled3 (line 38)
rmc = lteRMCDL(enb, ncw);
If the error you describe was preceded by:
Undefined function 'lteRMCDL' for input arguments of type 'struct'.
Then the most likely reason is that you do not have the LTE system toolbox, or that you have an older version which does not contain that function.
You can check which version of MATLAB you are running, and all the installed toolboxes you have along with their version number, by typing ver at the command line. Alternatively , you can check the location of a given function on the path by typing which lteRMCDL (this can help if the problem is that you have written a function with the same name as an existing MATLAB function, or if your MATLAB path is not set up correctly).
MATLAB online help shows by default the latest (2013b at time of writing) help and requires you to log in to show archived help files.

MATLAB error while evaluating uicontrol Callback

I have a MATLAB script that worked perfectly fine; there were no problems with it whatsoever. Then I moved it into the MATLAB toolbox and added it to the cache so I could run it easily from the command line.
However, now that I have moved it into the toolbox, I get these error messages! There were no changes to the script or anything. I moved all of the subfolders and other files related to the script with it.
I have no idea why it is giving me this error message. Even worse, it does not do it every time I run the script! Sometimes if I close MATLAB and open it again, the script runs fine. Sometimes all I have to do is click anything in the GUI and it works! But the next time it won't? Can you help me out here?
These are the two error messages it gives me:
??? Too many outputs requested. Most likely cause is missing [] around
left hand side that has a comma separated list expansion.
Error in ==> trials at 13
picture1 = files1.name;
Error in ==> semjudge>TRIAL_Callback at 285
trials;
??? Error using ==> waitfor
Error while evaluating uicontrol Callback
And:
??? Error using ==> nchoosek at 31
The first argument has to be a scalar or a vector.
Error in ==> semjudge>START_Callback at 194
combos = nchoosek(1:nFiles, 2);
??? Error using ==> waitfor
Error while evaluating uicontrol Callback
What causes these errors, such that they only SOMETIMES appear (without any change in the .m file or the GUI or anything ...)?
This is frustrating me to no end. It was working perfectly fine, and stopped despite no changes being made. And it is inconsistent whether or not it gives me the error. I can't find any pattern to when it does work, and when it doesn't. And neither of the errors that it DOES give me make any sense to me.
The .m file(s) are too long to post here, so you can see them, here:
http://textuploader.com/?p=6&id=cKokK (semjudge.m)
http://textuploader.com/?p=6&id=vB9sD (trials.m)
It seems your script is not always able to find certain image files.
In trials.m files1 is probably an empty struct array so the assignment to picture fails. This can be caused by dir not finding appropriate files.
In semjudge.m, if there are no files, nFiles is 0, so 1:nFiles is the empty array.