11. Troubleshooting
In previous years students have experienced various problems. We have collected some "frequently asked questions” with answers in the hope it will save you some time.
Question:
I tried to execute my M-file proj.m using >> proj but received
??? Undefined function or variable ’proj’.
or
I tried to use my function proj(x) held in proj.m but received
??? Can not find function ’proj’.
Error in ==> c:\\mat\toolbox\\mat\specgraph\fplot.m
On line 85 ==> x = xmin; y = feval(fun,x);
Reason:
You are not working in the same directory where the M-file proj.m is held.
Action:
Change directory or save the M-file into the correct directory .
******************************************************************************
Question:
I attempted to evaluate an elementary MATLAB function such as mod(101,7) (or another MATLAB function) but received the following message
??? ??? Error using ==> mod
Too many input arguments.
I then asked for help using help mod and received
No help comments found in mod.m.
Reason:
Both responses indicate that you have inadvertently named one of your own M-files mod.m previously. It has taken precedence over MATLAB ’s inbuilt function.
Action:
Change the name of your own M-file to one that does not exist in MATLAB .
******************************************************************************
Question:
Why do I receive one of the following error messages, or similar?
??? Error using ==> .*
Matrix dimensions must agree.
or
??? Error using ==> plot
Vectors must be the same lengths.
Reason:
When doing a calculation involving two arrays, or graphing using the plot command, the arrays must be of the same size.
Action:
Check the size of each array involved.
******************************************************************************
Question:
Why did I not get any numbers printed on the screen?
Reason:
Semicolons at the end of a MATLAB assignment statement prevent answers being displayed.
Action:
Leave off semicolons where you want numbers to be shown in the output.
******************************************************************************
Question:
Why did I get thousands of numbers printed on the screen?
Reason:
Semicolons at the end of a MATLAB assignment statement prevent answers
being displayed.
Action:
Place semicolons where you do not want numbers to be shown in the output.
******************************************************************************
Question:
Why do I continually get the following error message?
??? Error using ==> ^
Matrix must be square.
or
??? Error using ==> *
Inner matrix dimensions must agree.
Reason:
You have asked for something like x^2 or f(x)*g(x) where x is currently an array. It is only possible to square an array x or multiply f(x)*g(x) if x is a square matrix.
Action:
If you think x is a scalar variable, it is possible that you were also using the same symbol to represent an array and forgot to clear it. But more likely x is an array and you should be using the dot notation x.^2 or f(x).*g(x). The location might be in a script M-file or, more obscurely, in a function M-file where you did not allow for later array evaluations.
******************************************************************************
Question:
Why are parts of my graphical figures missing?
Reason:
You have probably lost graphs or graphical components.
Action:
Make sure each figure is numbered. Within a figure, use the hold on . . . hold off facility to avoid losing command outcomes.
******************************************************************************
Question:
When I access a function M-file, either by doing an evaluation after the >> prompt or else calling from another M-file, why do I get no answer back or else receive the empty answer: [ ] ?
Reason:
Although the first line in your function M-file was of the form
function y=fred(x)
you have not assigned any value to y during the file.
Action:
Make sure output variables are given values in function M-files.
******************************************************************************
Question:
When using solve on a transcendental equation in “Maple”, why do I get complex solutions, or else a real solution which is not the one I want?
Reason: Consider, for example, the equation xex + x3 −2 = 0. Using
syms x , ans=solve(x*exp(x)+x^3-2)
yields a complex solution only.
Action:
Use fzero in MATLAB instead. If the function has been defined in func.m, then ans=fzero(@func,[0 1]) yields ans=0.7482 which is probably the solution you were seeking within the specified interval.