Thread Subject:
Matlab errors

Subject: Matlab errors

From: Abdo

Date: 17 Mar, 2012 23:10:29

Message: 1 of 4

hello everyone I'm new here and I was wandering if you could help me with this program...

My code:

function o = convertSingletoOctal(bs)
F2=zeros(1,23);
e2=zeros(1,8);
for i=10:32
F2(i-9)=bs(i);
end
for i=2:9
e2(i-1)=bs(i);
end
[E8,F8,e8]=Convert2to8Exp(F2,e2);%Calling the function Convert2to8Exp
t=bs(1);
if t == 1
o=disp(['o = - ', num2str(E8),'.',num2str(F8),' * 8^',num2str(e8)]);
elseif t == 0
o=disp(['o = + ', num2str(E8),'.',num2str(F8),' * 8^',num2str(e8)]);
end
end









Convert2to8Exp function=

function [E8,F8,e8]=Convert2to8Exp(F2,e2)
[E,F,e]= ShiftBinary(F2,e2);%Calling the function
%Converting the integral part
r=e2-e;
if(r==0)
    E=[0 0 E];
elseif(r==1)
    E=[0 E];
end
E8=(E(1)*2^2)+(E(2)*2)+E(3);

%Converting the fractional part
k =length(F);
re=rem(k,3);
if(re==1)
    F=[F 0 0];
elseif(re==2)
    F=[F 0];
end
k1 = length(F);
o = k1/3;%number of octal triplets
F8=zeros(1,8);
for i=1:o
F8(i)=F(3*i-2)*2^2+F(3*i-1)*2+F(3*i);
end
%Computing the exponent
e8=e/3;
end






Shift Binary function:

function [E , F, e] = ShiftBinary(F2, e2)
q = floor (e2/3);
r = rem (e2,3);
if (r==1)
    E= [1 F2(1)];
    F= F2(2:(length(F2)));
elseif (r==2)
    E= [1 F2(1) F2(2)];
    F= F2(3:(length(F2)));
elseif (r==0)
    E= 1;
    F= F2(1:length(F2));
end
e = 3 * q;
end












The error:

Error in ==> ShiftBinary at 7
q = floor (e2/3);

??? Output argument "E" (and maybe others) not assigned during call to
"C:\Users\ABDO\Documents\MATLAB\ShiftBinary.m>ShiftBinary".

Error in ==> Convert2to8Exp at 8
[E,F,e]= ShiftBinary(F2,e2);%Calling the function

Error in ==> convertSingletoOctal at 14
[E8,F8,e8]=Convert2to8Exp(F2,e2);%Calling the function Convert2to8Exp





Thank you for your help

Subject: Matlab errors

From: ImageAnalyst

Date: 18 Mar, 2012 00:20:25

Message: 2 of 4

You should learn how to use the debugger. If you knew how to do that
you could progress through your program one line at a time. Then
you'd notice that none of your if blocks was ever entered, thus E and
F were never assigned. They need to be because you return them.
Apparently the remainder of e2 and 3 is never an integer. e2 if
probably a floating point number. In that case, you need to read and
understand the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

Again, I HIGHLY recommend that you learn how to use the debugger.
Everyone here who is successful with MATLAB has learned how in a short
time.

Subject: Matlab errors

From: Roger Stafford

Date: 18 Mar, 2012 03:40:20

Message: 3 of 4

"Abdo " <aea11@aub.edu.lb> wrote in message <jk35l5$sc0$1@newscl01ah.mathworks.com>...
> ........
> function [E , F, e] = ShiftBinary(F2, e2)
> q = floor (e2/3);
> r = rem (e2,3);
> if (r==1)
> E= [1 F2(1)];
> F= F2(2:(length(F2)));
> elseif (r==2)
> E= [1 F2(1) F2(2)];
> F= F2(3:(length(F2)));
> elseif (r==0)
> E= 1;
> F= F2(1:length(F2));
> end
> e = 3 * q;
> end
> ........
- - - - - - - - -
  There appears to be a serious misunderstanding about bit strings in this code. In the 'convertSingletoOctal' function eight elements from 'bs' (apparently standing for a "bit string") are copied into the eight-element row vector 'e2'. Then 'e2' is passed over to 'Convert2to8Exp' and unchanged on over to 'ShiftBinary'. At that point, as nearly as I can make out, 'e2' is suddenly regarded as a single numerical quantity for which it is to be decided what its remainder is after being divided by 3 in preparation for conversion to an octal exponent.

  The immediate cause of the error message is that an 'if' statement, as in the line "if (r==1)", when faced with a multiple-element logical row vector will insist that all of these be true to satisfy the 'if' condition. Since none of the three conditions (r==1), (r==2), and (r==0) were apparently true for all eight elements simultaneously, then none of the needed actions in returning E, and F were carried out. Hence the message.

  However far more serious than this is the treatment of the string of eight bits as a single numerical quantity. This code will require some extensive overhaul for it to function properly, in my opinion.

Roger Stafford

Subject: Matlab errors

From: Greg Heath

Date: 18 Mar, 2012 09:54:06

Message: 4 of 4

On Mar 17, 7:10 pm, "Abdo " <ae...@aub.edu.lb> wrote:
> hello everyone I'm new here and I was wandering if you could help me with this program...
>
> My code:
>
> function o = convertSingletoOctal(bs)
> F2=zeros(1,23);
> e2=zeros(1,8);
> for i=10:32
> F2(i-9)=bs(i);
> end
> for i=2:9
> e2(i-1)=bs(i);
> end
> [E8,F8,e8]=Convert2to8Exp(F2,e2);%Calling the function Convert2to8Exp
> t=bs(1);
> if t == 1
> o=disp(['o = - ', num2str(E8),'.',num2str(F8),' * 8^',num2str(e8)]);
> elseif t == 0
> o=disp(['o = + ', num2str(E8),'.',num2str(F8),' * 8^',num2str(e8)]);
> end
> end
>
> Convert2to8Exp function=
>
> function [E8,F8,e8]=Convert2to8Exp(F2,e2)
> [E,F,e]= ShiftBinary(F2,e2);%Calling the function
> %Converting the integral part
> r=e2-e;
> if(r==0)
>     E=[0 0 E];
> elseif(r==1)
>     E=[0 E];
> end
> E8=(E(1)*2^2)+(E(2)*2)+E(3);
>
> %Converting the fractional part
> k =length(F);
> re=rem(k,3);
> if(re==1)
>     F=[F 0 0];
> elseif(re==2)
>     F=[F 0];
> end
> k1 = length(F);
> o = k1/3;%number of octal triplets
> F8=zeros(1,8);
> for i=1:o
> F8(i)=F(3*i-2)*2^2+F(3*i-1)*2+F(3*i);
> end
> %Computing the exponent
> e8=e/3;
> end
>
> Shift Binary function:
>
> function [E , F, e] = ShiftBinary(F2, e2)
> q = floor (e2/3);
> r = rem (e2,3);
> if (r==1)
>     E= [1 F2(1)];
>     F= F2(2:(length(F2)));
> elseif (r==2)
>     E= [1 F2(1) F2(2)];
>     F= F2(3:(length(F2)));
> elseif (r==0)
>     E= 1;
>     F= F2(1:length(F2));
> end
> e = 3 * q;
> end
>
> The error:
>
> Error in ==> ShiftBinary at 7
> q = floor (e2/3);
>
> ??? Output argument "E" (and maybe others) not assigned during call to
> "C:\Users\ABDO\Documents\MATLAB\ShiftBinary.m>ShiftBinary".
>
> Error in ==> Convert2to8Exp at 8
> [E,F,e]= ShiftBinary(F2,e2);%Calling the function
>
> Error in ==> convertSingletoOctal at 14
> [E8,F8,e8]=Convert2to8Exp(F2,e2);%Calling the function Convert2to8Exp
>
> Thank you for your help

How would you feel if someone asked you to find mistakes in a long,
sparsely
commented, code without telling you what the program is supposed to do
and
how you are trying to accomplish the task?

Greg

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us