MATLAB Guide tries to run nonexistent function - matlab

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.

Related

Simulink XCP DWARF Parser internal error: Parser::describeSymbol xcpDummyDoubleVariable is not a global variable

I'm currently changing Simulink Ext Mode to xcp. Now i'm running into the Issue DWARF Parser internal error: Parser::describeSymbol xcpDummyDoubleVariable is not a global variable. According to this post, the issue should have been fixed but it still doesn't work.
https://de.mathworks.com/matlabcentral/answers/703597-dwarf-parser-internal-error-parser-describesymbol-xcpdummydoublevariable-is-not-a-global-variable
I also tried the first approach (the second one is already active in version 22b) but the Error still occurs.
Have u got any suggestions why the error still occurs?

stand alone matlab .exe cannot call functions successfully

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?

Can I put a try-catch in GUI initialization code?

I am building a GUI in MATLAB (2016a) which I will be compiling and deploying. I want to try to do some global error handling, and it occurs to me that any command given to the GUI (button click, etc) first goes through the main initialization code before going to the specific Callback function. My thought was to put a try-catch block around the calls to gui_mainfcn. What's making me hesitate is that the code is bookended by some big old warnings:
% Begin initialization code - DO NOT EDIT
... initialization code here ...
% End initialization code - DO NOT EDIT
Could I break something by putting a try-catch block inside this initialization section? Is there a better way to attempt global error handling for a single GUI?
There is no reason that you can't insert global error handling in the main function of your GUIDE GUI. The warnings are really there to prevent people from inadvertently disrupting GUI functionality. In your case, a try/catch isn't going to actually modify the functionality so you're fine. You just want to be sure to not remove the calls to gui_mainfcn which is an internal function which contains all of the GUI logic.
Aside from that, you will also want to ensure that all requested output arguments are populated so that in the case of an error (for a function call where an output argument is expected) no error (within your catch block) is thrown because of that. That should be easy enough though
Also, I would only wrap the calls to gui_mainfcn
try
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
catch ME
% Go ahead and fill in the requested outputs with [] so we don't get an error
[varargout{1:nargout}] = deal([]);
% Do special error handling here
fprintf('Caught error: %s\n', ME.message);
end

Error using A3_4 (line 6) Not enough input arguments

This is my code:
%Activity 3.4 An object is thrown vertically with a speed vo reaches at
%height h at a time t.
function t = time(h,vo,g)
t = roots([0.5*g,-vo,h])
%Testing the function
test = time(100,50,9.81)
I've looked through different solutions but still can't figure out why I keep getting this error.
The error is happening on the line t = roots([0.5*g,-vo,h]).
Three comments:
You are probably pushing the Play button in the MATLAB editor. Don't do that. Forget that it even exists. Define h, vo and g in your Command Prompt, then do t = time(h, vo, g); in the Command Prompt. Again, do not push the Play button.
Make sure your working directory is set to where you defined the function time. MATLAB can't find this function that you defined. If you don't know how to do that, check out this from MathWorks: http://www.mathworks.com/help/matlab/ref/cd.html
Your error says it's trying to use a file called A3_4, yet your function is called time. In other words, It looks like you called your file A3_4.m yet it needs to be called time.m. Make sure it's in a file called time.m, then try again. That's one of MATLAB's cardinal rules. When you define a function, the function name and file name need to match.
Do all of those three steps in order, and you will be laughing and singing like these guys below:
(source: kym-cdn.com)

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.