stand alone matlab .exe cannot call functions successfully - matlab

I designed a GUI and called some functions defined in CVX software package.(I have already installed the CVX software package). When running the .m file, the functions could be called successfully. However, if converting the .m file into .exe, something went wrong, showing the following error message
Struct contents reference from a non-struct array object.
error cvx_global (line 76)
error cvxprob (line 4)
error cvx_begin (line 41)
Line 76 of cvx_global.m is:
osolvers = cvx___.solvers.list;
How can the problem be solved?

Related

How to get details in Matlab/Simulink about the error "Struct contents reference from a non-struct array object"?

I have a model designed with Matlab/Simulink R2017a and it is running well with no errors or warning messages in Diagnostic Viewer or MATLAB Command Window when I run it diretly from the Simulink.
However, when I start a build process on ConfigurationDesk from dSPACE to use this model in an embedded application the build process is aborted and the following message is shown:
Could not generate model code for model 'Model'. See MATLAB Command Window for details.
In MATLAB Command Window the following message is shown:
Struct contents reference from a non-struct array object.
================================================================================
Aborted Model-Code Generation for Model "Model".
================================================================================
As you can observe In MATLAB Command Window, there is no enough details about the error and due that I'm not being able to fix it.
There is any way to get more details about the error in order to track down it?
Thank you so much in advanced!

MATLAB Guide tries to run nonexistent function

I was making a GUI using GUIDE in Matlab. My computer froze and Matlab crashed. When I went to reopen GUIDE, I get the following error:
Undefined function or variable 'badfcn_CreateFcn'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in quick_gui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>#(hObject,eventdata)quick_gui('badfcn_CreateFcn',hObject,eventdata,guidata(hObject))
However, this function badfcn_CreateFcn does not exist anywhere in my gui.m file. There is also no object in my gui with this tag or description.
Is there a way to fix this?
The issue was that the tag of a ui object had been changed, but the Callback and Create functions were using the old tag name. This won't be apparent in the object browser. Since I have everything in panels, I did what #marco wassmer recommended and created the function with a breakpoint. This is how I found that the object was residing in Panel X. I went through all objects in Panel X and sure enough, one of them was using the badfcn tag for the Callback and Create functions even though the tag name was different.

Matlab Parallel Computing with Simulink Model

I'm working on a project in which parallel computing would be a huge advantage. The project simulates multiple Simulink models. I did the simulation with a normal for-Loop, but since it takes days to simulate I decided to try the "parfor"-Loop.
But that's where the problem begins. First I'll give you pictures of my code, the workspace and the Simulink-part which is causing me problems:
Here's my code:
apool = gcp('nocreate');
if isempty(apool)
apool = parpool('local');
end
wpath = pwd;
parfor k = 1:number_of_models
load_system(strcat(wpath,'\Models_Folder\',House(k).model_name));
set_param(House(k).model_name, 'Stoptime', num2str(foreruntime));
set_param(House(k).mask_name, 'Data_contr', num2str(controlvector(k)));
set_param(House(k).mask_name, 'Data_cons', strcat('GlobalData(',num2str(k),').consume.',MaskParam(k).consume_input))
SimOut(k) = sim(House(k).model_name);
end
delete(apool);
The confusing thing is if i delete the column:
SimOut(k) = sim(House(k).model_name);
the code just works fine -> the modelparameters are set in a parfor loop
but if I don't delete the column the following error appears:
Error using Forerunsimple (line 9)
Error evaluating parameter 'Data_cons' in 'model_house_14/House'
Caused by:
Error using parallel_function>make_general_channel/channel_general (line 907)
Error evaluating parameter 'Data_cons' in 'model_house_14/House'
Error using parallel_function>make_general_channel/channel_general (line 907)
Undefined variable "GlobalData" or class "GlobalData".
As you can see in the picture the variable "GlobalData" is defined in the workspace. So in my opinion it should work. Obviously it doesn't. Do you have any idea what could be the problem?
you may want to see this question, IMHO, it is related, and could in fact be the same problem:
MATLAB: What happens for a global variable when running in the parallel mode?
There a workspace global variable appears to be empty, even if it was defined.
user Edric provides a link, and a short explanation, that global variables are not passed to workers (for instance simulink running as parallel).
The link is to this blog entry: "Getting parfor loops up and running":
http://blogs.mathworks.com/loren/2009/10/02/using-parfor-loops-getting-up-and-running/

Matlab beginner: function that iterates a matrix

I am a beginner of Matlab. I am trying to run this function but there seem to be a syntax error that I cannot understand. The source code is the following.
function print_trace(x)
for rowi=1:size(x,1),
for coli=1:size(x,2),
disp(x(rowi,coli))
end
end
The error encountered is the following:
??? Input argument "x" is undefined.
Error in ==> print_trace at 2
for rowi=1:size(x,1),
Any ideas?
EDIT: here is a screenshot: http://imgur.com/pwPhzhh
EDIT 2:
Trying to see if there are multiple copies running:
>> which('print_trace')
C:\Users\stablum\Dropbox\cm\print_trace.m
EDIT: solution of the problem :)
it seems that I solved the problem, my mistake was running ("play" button) the file of the function instead of just calling the function (which will load the file automatically). I still don't understand why there was this error when the file is run, but at least my problem is solved.
I suppose it is because of the way you call the function.
The error indicates that you don't give the required parameter x. Especially, you seem t o call the function with
print_trace()
or
print_trace
or
print_trace(empty_cell{:})
which leads to the effect that there is no value to be assigned to x.

How can matlab be unable to find an anonymous function?

I get a strange error when running my script:
Unable to find function #(x) exp(x) within H:\blabla\myClass.m.
when I debug I get:
34 b=myAnonymousFunction(a)
K>> myAnonymousFunction(3)
Unable to find function #() exp(x) within HH:\blabla\myClass.m.
K>> class(myAnonymousFunction)
ans =
function_handle
A minimal example I was trying to produce worked fine.
Do You have any Idea where the error comes from and what it means?
Because he obviously can find the definition of insanity...ahh... myAnonymousFunction. Is it just a bug? I read something on matlabcentral but its 7 Years old and doesn't give an explanation.
Further explanation:
I'm running MATLAB 2012 b under Windows 8 64 bit. The source files were originally written under a 64 bit Linux.
I don't think it's relevant but myAnonymousFunction is a parameter to a function in myClass and stored within a cell array. So it's like this:
file myClass.m:
classdef myclass < handle
properties
x=1337;
myAnonymousFunctions;
end
methods
function new = myClass(myAnonymousFunctions)
new.myAnonymousFunction=myAnonymousFunction
end
function show(o)
disp(myAnonymousFunction{1}(o.x));
end
end
end
and gets called like
myMyclass = myClass({#(x)exp(x)})
myMyClass.f();
Possible Workaround: restart Matlab.
After restarting MATLAB the Problem didn't occur ... so far.
I guess buggy ML debugger was buggy.
I also received the same error when using an anonymous function in a class. The function was stored as a field inside a Matlab class as:
dataBlockObj.processStream(dataBlockObj.activeProcessStreamIndex).func=#(x) x;
and I had been debugging the code, however the error occurred while I was running the code on the command line without any breakpoints set. The solution for me was also restarting Matlab. I was running Matlab 2012b 64bit on a Windows 2008 Server.