debugging a matlab code
Mostra commenti meno recenti
Hi,
I am attaching the folder with the relevant files for running a particular matlab code. In the file, there are two codes:
- "leisure.m"
- "main.m"
I have all the functions necessary, to run those.
The problem is that while the program "leisure" runs perfectly, the "clone" of it which which is the second one, it gives different errors messages without amending anything in particular. So, I fed up trying to debug the second program and would like to know whether someone can help. The two most common errors that showed up, are:
Operands to the and && operators must be convertible to logical scalar values.
Error in fminbnd (line 321)
if ( (fu <= fw) || (w == xf) )
Error in main_optimum_quantity (line 96)
k1 = fminbnd(@vf2,kmin,kmax);
and
Subscript indices must either be real positive integers or logicals.
The programs and functions are really small so does not take lot of effort to read.
Many thanks
7 Commenti
Geoff Hayes
il 27 Lug 2014
Safis - you did not include any files.
Are your inputs kmin and kmax scalars or arrays? Which line of code does the Subscript indices must either be real positive integers or logicals correspond to?
per isakson
il 27 Lug 2014
Did you try
dbstop if error
and inspect the values at the "stop"?
per isakson
il 27 Lug 2014
First step:
>> main
Operands to the || and && operators must be convertible to logical scalar values.
Error in fminbnd (line 321)
if ( (fu <= fw) || (w == xf) )
Error in main (line 98)
k1 = fminbnd(@vf2,kmin,kmax);
K>> fu
fu =
Empty matrix: 1-by-0
K>>
Next step is find out why fu is empty.
 
The reason for
Subscript indices must either be real positive integers or logicals.
is often an empty variable.
Regarding the first error: Try,
a = 1 && 0
b = [1,0] & [1,1]
c = isequal([1,0], [1,1])
d = [1,0] && [1,1];
I you are expecting scalar you must have a look in your code and find out where your code gives a wrong answer, otherwise if you only have used the wrong syntax it is easy to fix.
msh
il 28 Lug 2014
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Entering Commands in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!