You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
datatypes
5 views (last 30 days)
Show older comments
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?
Accepted Answer
Walter Roberson
on 13 May 2011
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.
26 Comments
sheen
on 14 May 2011
thanx for such a nice description . but i am facing another problem in the following code:
% high weights of current project
j = [1.15,1.08,1.15,1.11,1.06,1.15,1.07,1.07,0.91,0.86,0.90,0.95,0.91,0.91,1.04];
% nominal weights of previous project
l = [1.00, 1.00 , 1.00 ,1.00, 1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00];
m = [1.05,1.12,1.2];
% float z[53]= [46,16,4,6.9,22,30,18,20,37,24,3,3.9,3.7,1.9,75,90,38,48,9.4,13,2.14,1.98,50,40,22,13,12,34,15,6.2,2.5,5.3,19.5,28,30,32,57,23,91,24,10,8.2,5.3,4.4,6.3,27,15,25,21,6.7,28,9.110];
t = 17;
% size
for i = 0:2
y = z(i)
end
% cost drivers
for k = 0 : j
x = j(k)
end
% project modes
for n = 0 : 2
a = m(n)
end
% sum of importance weights of current project
double s = a + x + y;
b = s / t;
for c = 0 : l
h = l(c)
end
% sum of importance weights of previous project
e = a + d+ y;
double f = e / t;
p = 24.5 ;
g = f * p;
% indivisual distance
d = b - g;
display (d)
error is:
??? Undefined command/function 'z'.
Error in ==> f at 21
y = z(i)
please tell me what shoud i do with it?
Walter Roberson
on 15 May 2011
There are numerous errors in your code. Try
% high weights of current project
j = [1.15, 1.08, 1.15, 1.11, 1.06, 1.15, 1.07, 1.07, 0.91, 0.86, 0.90, 0.95, 0.91, 0.91, 1.04];
% nominal weights of previous project
l = [1.00, 1.00 , 1.00 ,1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00];
m = [1.05, 1.12, 1.2];
z = [46, 16, 4, 6.9, 22, 30, 18, 20, 37, 24, 3, 3.9, 3.7, 1.9, 75, 90, 38, 48, 9.4, 13, 2.14, 1.98, 50, 40, 22, 13, 12, 34, 15, 6.2, 2.5, 5.3, 19.5, 28, 30, 32, 57, 23, 91, 24, 10, 8.2, 5.3, 4.4, 6.3, 27, 15, 25, 21, 6.7, 28, 9.110];
%You might want a comma between the 9.1 and 10 that follows above??
t = 17;
%size
y = z(1:3);
% cost drivers
%for k = 0 : j %what was this intended to mean??
x = j(1:3); %guessing here
% project modes
a = m(1:3);
% sum of importance weights of current project
s = a + x + y;
b = s / t;
%for c = 0:1 %what was this intended to mean??
h = l(1:2); %guessing, but it is never used anyhow
% sum of importance weights of previous project
e = a + d + y;
f = e / t;
p = 24.5 ;
g = f * p;
% individual distance
d = b - g;
disp(d)
sheen
on 15 May 2011
% high weights of current project
j = [1.15, 1.08, 1.15, 1.11, 1.06, 1.15, 1.07, 1.07, 0.91, 0.86, 0.90, 0.95, 0.91, 0.91, 1.04];
% nominal weights of previous project
l = [1.00, 1.00 , 1.00 ,1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00];
m = [1.05, 1.12, 1.2];
z = [46, 16, 4, 6.9, 22, 30, 18, 20, 37, 24, 3, 3.9, 3.7, 1.9, 75, 90, 38, 48, 9.4, 13, 2.14, 1.98, 50, 40, 22, 13, 12, 34, 15, 6.2, 2.5, 5.3, 19.5, 28, 30, 32, 57, 23, 91, 24, 10, 8.2, 5.3, 4.4, 6.3, 27, 15, 25, 21, 6.7, 28, 9.1,10];
t = 17;
%size
y = z(1:3);
%for k = 0 : j % its mean that I will take 12 values of matrix j in loop ok k and store these values in x, so I could use x in further calculations and whole 12 values will be used one by one by loop vie variable x.same is the case with other for loops..
x = j(k);
end % end is omitted by you? Is there no need to use it?
for n = 0 : 2
a = m(n)
end
% sum of importance weights of current project
s = a + x + y;
b = s / t;
for c = 0 : l
h = l(c)
end
% sum of importance weights of previous project
e = a + d + y;
f = e / t;
p = 24.5 ;
g = f * p;
% individual distance
d = b - g;
disp(d)
plz check it.
sheen
on 15 May 2011
% high weights of current project
j = [1.15, 1.08, 1.15, 1.11, 1.06, 1.15, 1.07, 1.07, 0.91, 0.86, 0.90, 0.95, 0.91, 0.91, 1.04];
% nominal weights of previous project
l = [1.00, 1.00 , 1.00 ,1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00];
m = [1.05, 1.12, 1.2];
z = [46, 16, 4, 6.9, 22, 30, 18, 20, 37, 24, 3, 3.9, 3.7, 1.9, 75, 90, 38, 48, 9.4, 13, 2.14, 1.98, 50, 40, 22, 13, 12, 34, 15, 6.2, 2.5, 5.3, 19.5, 28, 30, 32, 57, 23, 91, 24, 10, 8.2, 5.3, 4.4, 6.3, 27, 15, 25, 21, 6.7, 28, 9.1,10];
t = 17;
%size
y = z(1:3);
%for k = 0 : j % its mean that I will take 12 values of matrix j in loop ok k and store these values in x, so I could use x in further calculations and whole 12 values will be used one by one by loop vie variable x.same is the case with other for loops..
x = j(k);
end % end is omitted by you? Is there no need to use it?
for n = 0 : 2
a = m(n)
end
% sum of importance weights of current project
s = a + x + y;
b = s / t;
for c = 0 : l
h = l(c)
end
% sum of importance weights of previous project
e = a + d + y;
f = e / t;
p = 24.5 ;
g = f * p;
% individual distance
d = b - g;
disp(d)
plz check it.
Walter Roberson
on 15 May 2011
What was your original C code that you translated in to
for n = 0 : 2
a = m(n)
end
?
sheen
on 18 May 2011
i didnt convereted c code but i am working on an algorithm , in which three modes are to entered as input.for those modes i took a for loop from 0 to 2 and stored it in array m by indexing it as n and storing this array in a.so i could use a in further formul for further calculations.
sheen
on 18 May 2011
as u see in equation e = a+x+y , a is used for calculation, so here three modes are taken one by one and values are calculated. please tell me why answer is wrong i.e. -66.6294 -25.1588 -8.7779.
while i need one value between 0 and 1.what should i do?
Walter Roberson
on 19 May 2011
How can you add three values, two of which are strictly greater than 1 and the other of which is strictly greater than 0, and expect to get an answer between 0 and 1 ???
sheen
on 20 May 2011
% high weights of current project (cost drivers)
j = [1.15, 1.08, 1.15, 1.11, 1.06, 1.15, 1.07, 1.07, 0.91, 0.86, 0.90, 0.95, 0.91, 0.91, 1.04];
% nominal weights of previous project
l = [1.00, 1.00 , 1.00 ,1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00];
%mode
m = [1.05, 1.12, 1.2];
% size
z = [46, 16, 4];% 6.9, 22, 30, 18, 20, 37, 24, 3, 3.9, 3.7, 1.9, 75, 90, 38, 48, 9.4, 13, 2.14, 1.98, 50, 40, 22, 13, 12, 34, 15, 6.2, 2.5, 5.3, 19.5, 28, 30, 32, 57, 23, 91, 24, 10, 8.2, 5.3, 4.4, 6.3, 27, 15, 25, 21, 6.7, 28, 9.110];
t = 17;
%size
for z = 1:3
y{z} = 1 : z;
end
% cost drivers
for j = 1:15
x{j} = 1:j ;
end
% project modes
for m = 1 :3
a{m} = 1:m;
end
% sum of importance weights of current project
s = a{m} + x{j} + y{z};
b = s / t;
%cost drivers of previous project
for l = 1:2
h{l} = 1 :l;
end
% sum of importance weights of previous project
e = a{m} + h{l} + y{z};
f = e / t;
p = 24.5 ;
g = f * p;
% individual distance
d = b - g;
disp(d)
error:
??? Error using ==> plus
Matrix dimensions must agree.
Error in ==> efff at 36
s = a{m} + x{j} + y{z};
how to handle it? please reply soon.
Walter Roberson
on 20 May 2011
In your case, I would start by going back and writing pseudo-code to describe what you are trying to do.
sheen
on 21 May 2011
the pseudo-code of my m-file is given below:
Calculate similarity between software projects
Require Q , the Proportion of individual distances
Require k and j, describing software project
Require uk , the importance weight associated with Kth variable
Require M, describing the number of variables describing the software project
Require T, the total sum of all importance weights uk
Require dvj (P1,P2) , describing individual distance
Compute d(P1,P2)
S = ∑_(k=1)^j▒u_k , sum of current project’s importance weights
A = S/T, T is Total sum of all importance weights u_k
Q(A) where Q = 1
C = ∑_(j=1)^M▒〖Q(A)〗
Compute B = ∑_(k=1)^(j-1)▒u_k , sum of previous project’s importance weights
D1 = B/T
D2=D1(Q)
D3 = D2 (dvj (P1,P2)) where dvj (P1,P2) = {█(max min (µ_(Aj_k ) (P_1) ,µ_(Aj_k ) (P_2))@max-min aggregation@∑_k▒〖µ_(Aj_k ) (P_1) x µ_(Aj_k ) (P_2)〗@Sum-product aggregation)┤
D4= C – D3 \\ individual distance
Walter Roberson
on 21 May 2011
I cannot make out what some of those symbols are. In the expression for S, I cannot make out the symbol(s) between the ^j and the u_k . I also cannot tell why the underscore appears after the sigma.
In the expression for C, the same symbol appears to ocur. Then there is what seems to be some kind of brackets around Q(A) but I cannot tell if that is, for example, a symbol for "complex conjugate".
In the D3 like, thee is something I cannot make out between the { and the "(max", and those odd brackets appear again, and the line ends in something I am not sure I understand but which appears to be dash followed by "|" ?
I don't understand what the @ mean anywhere in the formula.
Please use only ASCII symbols, or else link to a URL that has the formula as a diagram and which indicates the meaning of any unusual symbols.
I probably will not reply all that soon: after weeks of nasty weather we finally have a warm clear evening, so I have yard-work duties.
Walter Roberson
on 21 May 2011
*Any* file sharing site that doesn't require us to register and log on to see the files.
Walter Roberson
on 21 May 2011
Don't post people's email address without their permission.
I will see if I can put together a list of sites people use.
Walter Roberson
on 21 May 2011
See http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
sheen
on 21 May 2011
d (P1, P2) =
M j j-1
∑ Q( (∑ (u )/T) - Q ((∑ (u )/T) * d v (P1,P2)
(j=1) (k=1) k (k=1) k j
i have written code for this eq.
j=1 is subscrtipt of first summation.and M is superscript of first summation and so on.i hope u will understand my problem now.for u with k as subscrit , i have taken size, modes and cost drivers.please tell me how to correct my code?
More Answers (1)
Sean de Wolski
on 13 May 2011
You don't need to declare them as double; it's automatic.
e1 = 107;
e2 = e1 * 339;
disp(e2/e1)
6 Comments
sheen
on 14 May 2011
thanx a lot.but i dont need to declare it then why it is giving error in the following:
% high weights of current project
j = [1.15,1.08,1.15,1.11,1.06,1.15,1.07,1.07,0.91,0.86,0.90,0.95,0.91,0.91,1.04];
% nominal weights of previous project
l = [1.00, 1.00 , 1.00 ,1.00, 1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00];
m = [1.05,1.12,1.2];
% float z[53]= [46,16,4,6.9,22,30,18,20,37,24,3,3.9,3.7,1.9,75,90,38,48,9.4,13,2.14,1.98,50,40,22,13,12,34,15,6.2,2.5,5.3,19.5,28,30,32,57,23,91,24,10,8.2,5.3,4.4,6.3,27,15,25,21,6.7,28,9.110];
t = 17;
% size
for i = 0:2
y = z(i)
end
% cost drivers
for k = 0 : j
x = j(k)
end
% project modes
for n = 0 : 2
a = m(n)
end
% sum of importance weights of current project
double s = a + x + y;
b = s / t;
for c = 0 : l
h = l(c)
end
% sum of importance weights of previous project
e = a + d+ y;
double f = e / t;
p = 24.5 ;
g = f * p;
% indivisual distance
d = b - g;
display (d)
error:
??? Undefined command/function 'z'.
Error in ==> f at 21
y = z(i)
Walter Roberson
on 15 May 2011
You do not need to *declare* variables, but you still need to initialize them!
What constant 339??
If you have the Fuzzy Logic Toolbox, then Yes, you can call upon it to calculate values that will be used in this routine.
See Also
Categories
Find more on Financial Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)