[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Bizarre Error
From: |
pand9613 |
Subject: |
RE: Bizarre Error |
Date: |
Wed, 12 Feb 2003 18:22:39 +1100 |
User-agent: |
Internet Messaging Program (IMP) 3.0 |
Yes, sorry i did mean str2num. As you say str2num produces the result as you
said. I am not disputing this fact.It is in the next operation of the while
loop the the error occurs.
Also sorry about the uncommented code...a bad habit i haven't gotten out of. I
have done a rush job of commenting in a dodgy text editor so apologies if the
format is a little disorganised. I'll outline the problem in detail at the
bottom. This email is quite long so bear with me...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Cmat]=getmat
% Ex is a variable that when set to 1 exits this and all all functions that
% call this
global Ex
%sets the current page to 1
Cpage=1;
%Reads in the contents of the directory 'Materials' as a string array
filelist=readdir('Materials');
%Creates a string array of files with the extension 'mtl'
mtlfiles=fnmatch('*.mtl',filelist);
mtlfiles=find(mtlfiles==1);
filelist=filelist(mtlfiles,:);
%Initiates a continous loop while the exit variable is 0
while Ex==0;
%Error check for the existence of 'mtl' files in directory 'Materials'
%if none exist the function exits (although doesn't exit the higher level
%functions since the variable Ex is not changed)
if isempty(filelist)==1
disp('No saved files')
return
else
%if files exist then this code sets up a the start point and finish
%point of files to be displayed in the list ie if Cpage = 2 then
%Cpage_start =11 and Cpage_finish=20
Cpage_start= ((Cpage-1)*10+Cpage);
%If the last file is on the current page sets Cpage_finish to be that row
%rather than Cpage*10
if (Cpage*10)>length(mtlfiles)
Cpage_finish=length(mtlfiles);
else Cpage_finish=(Cpage*10);
end
%Loads the variable 'matname' from inside each of the 'mtl'
%files on the current page and displays each with a number representing
%its position on the list.
disp('\n* Available Files *\n')
matlist='';
for i=Cpage_start:Cpage_finish
%#################################################################
loadline=['load -force materials/',filelist(i,:),' matname'];
eval(loadline);
%#################################################################
matlist=[matlist;[num2str(i),'. ',matname]];
end
disp(matlist)
disp(sprintf('\n%.0f of %.0f Page(s)\n',Cpage,ceil
(length
(mtlfiles)/10)))
disp('Enter material number or (<>)to change page:\n\n
(b)ack\n (e)xit\n')
%Requests user input which is stored as a string
userin=input('>>','s');
%if the user enters b returns to the high level function
if userin=='b'
return
%if the user enters e then returns to the high level function and repeats
elseif userin=='e'
Ex=1;
return
%if the user enters > or <, checks to make sure there is a valid page number
%before or after the current and if so changes Cpage to that page.
elseif userin=='>'
Cpageok=Cpage+1;
if (Cpageok*10-10)>(length(mtlfiles)) |
Cpageok<=0
disp('\nInvalid page number\n')
else Cpage=Cpageok;
continue
end
elseif userin=='<'
Cpageok=Cpage-1;
if (Cpageok*10-10)>(length(mtlfiles)) |
Cpageok<=0
disp('\nInvalid page number\n')
else Cpage=Cpageok;
continue
end
%if user enters nothing then returns to the top of the code and begins the
%next operation of the while loop
elseif userin==''
continue
%Converts the userinput to a number
else userin=str2num(userin)
%if the input wasn't a number then it returns an empty string upon which the
% code returns to the while loop
%*********************************************************************
if userin==[]
disp('Invalid Input')
continue
end
%*********************************************************************
%if the user enters a number greater than that on the list then returns to
%the while loop.
if userin>length(mtlfiles)
disp('No such Material')
continue
%if these checks are okay assigns the row of filelist to a string Cmat which
%is the function output. Upon this it leaves the function and returns to the
% one that called it
else
Cmat=[filelist(userin,:)];
return
end
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The line marked with *'s is the one which checks for erroneous strings. It
outputs an empty matrix no matter what string is entered so long as it is not a
number. So this check returns the correct value and it should not matter what
string is entered for userin. Upon the next operation of the while loop a parse
error occurs in one of the two lines marked by the #'s. If the string entered
in for userin in the previous while operation is letters prefixed by a number
the error occurs. If the string is some other combination of letters, or
letters and numbers without a number at the beginning then the error does not
occur.
It seems strange because there are no variables redefined anywhere in the while
loop that could cause different operation in subsequent loops (on the program
flow path anyway).
Any ideas anyone?
Cheers,
Peter Anderson
Quoting Julian DeMarchi <address@hidden>:
> I do not get this error (Win2k, Octave 2.1.42). Witness:
>
> >> str2num('asdf')
> ans = []
> >> str2num('123asdf')
> ans = []
> >>
>
> - JD
> [ps Peter you mention num2str() but I think you meant str2num()]
>
>
> -----Original Message-----
> From: address@hidden [mailto:address@hidden
> Sent: Tue 2/11/2003 11:35 PM
> To: address@hidden
> Cc:
> Subject: Re: Bizarre Error
>
>
>
>
> Just to clarify:
> Entering an erroneous string beginning with numbers (but letters
following)
> produces an error while an erroneous string beginning with letters
(followed
> by
> other numbers or letters) does not.
> I am using windows 98 with cygwin, octave version 2.1.36
>
>
> -------------------------------------------------
> This mail sent through IMP: www-mail.usyd.edu.au
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web: http://www.octave.org
> How to fund new projects: http://www.octave.org/funding.html
> Subscription information: http://www.octave.org/archive.html
> -------------------------------------------------------------
>
>
>
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web: http://www.octave.org
> How to fund new projects: http://www.octave.org/funding.html
> Subscription information: http://www.octave.org/archive.html
> -------------------------------------------------------------
>
>
-------------------------------------------------
This mail sent through IMP: www-mail.usyd.edu.au
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Re: Bizarre Error, (continued)
Re: Bizarre Error, pand9613, 2003/02/11
RE: Bizarre Error, Julian DeMarchi, 2003/02/11
RE: Bizarre Error, Julian DeMarchi, 2003/02/11
- RE: Bizarre Error,
pand9613 <=
RE: Bizarre Error, Julian DeMarchi, 2003/02/12
RE: Bizarre Error, Julian DeMarchi, 2003/02/12