MATLAB: Datatypes

command syntaxconverting c to matlabfis

double e1,e2,e;
e1 = 107; e2 = e1 * 339;
disp(e2/e1)
error: The string being specified was neither 'single' nor 'double' ??? Undefined function or variable "e2".
Error in ==> ef at 1 float e1,e2,e;
ans =
101 49
??? Undefined function or variable "e2".
Error in ==> ef at 1 double e1,e2,e;
it is also giving problem with int and float?? what should i do to deal with this error?

Best Answer

Your command
double e1,e2,e;
is equivalent to
double('e1')
e2
e
'e1' is a string, which is an array of character, and applying double to the array of character returns the numeric values of each of the characters: that happens to be 101 for 'e' and 49 for '2'. For more information on this, please see Command vs Function syntax
In MATLAB, one does not declare variables as being of a particular type: one just assigns values and the variable assumes the type of the values if the variable appears by itself (without any kind of indexing) in an assignment syntax.