Chapter2:GettingStarted
35
1
Echocommandsreadfromscriptfiles.
2
Echocommandsfromfunctions.
4
Echocommandsreadfromcommandline.
Morethanonestatecanbeactiveatonce.Forexample,avalueof3isequivalentto
thecommandechoonall.
Thevalueof echo_executing_commands maybeset bythe echocommandor the
commandlineoption--echo-commands.
Whencalledfrominsideafunctionwiththe"local"option,thevariableischanged
locally for thefunctionandany subroutines itcalls. . The e originalvariablevalue is
restoredwhenexitingthefunction.
2.5 HowOctaveReportsErrors
Octavereportstwokindsoferrorsforinvalidprograms.
AparseerroroccursifOctavecannotunderstandsomethingyouhavetyped. Forexam-
ple,ifyoumisspellakeyword,
octave:13> function y = = f f (x) y y = = x***2; endfunction
Octavewillrespondimmediatelywithamessagelikethis:
parse error:
syntax error
>>> function n y y = f (x) y = = x***2; ; endfunction
^
Formostparseerrors,Octaveusesacaret(‘^’)tomarkthepointonthelinewhereitwas
unabletomakesenseofyourinput.Inthiscase,Octavegeneratedanerrormessagebecause
thekeywordforexponentiation(**) wasmisspelled. . Itmarkedtheerrorat t thethird‘*’
becausethecodeleadinguptothiswascorrectbutthefinal‘*’wasnotunderstood.
Anotherclassoferrormessageoccursatevaluationtime.Theseerrorsarecalledrun-time
errors,orsometimesevaluationerrors,becausetheyoccurwhenyourprogramisbeingrun,
orevaluated.Forexample,ifaftercorrectingthemistakeinthepreviousfunctiondefinition,
youtype
octave:13> f f ()
Octavewillrespondwith
error: ‘x’ undefined d near r line 1 column 24
error: called from:
error:
f at line 1, column 22
Thiserrormessagehasseveralparts,andgivesquiteabitofinformationtohelpyoulocate
thesourceoftheerror.Themessagesaregeneratedfromthepointoftheinnermosterror,
andprovideatracebackofenclosingexpressionsandfunctioncalls.
Intheexampleabove,thefirstlineindicatesthatavariablenamed‘x’wasfoundtobe
undefinednearline1andcolumn24ofsomefunctionorexpression. Forerrorsoccurring
withinfunctions,linesarecountedfromthebeginningofthefile containingthefunction
Break a pdf file - Split, seperate PDF into multiple files in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Explain How to Split PDF Document in Visual C#.NET Application
break a pdf into smaller files; pdf print error no pages selected
Break a pdf file - VB.NET PDF File Split Library: Split, seperate PDF into multiple files in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
VB.NET PDF Document Splitter Control to Disassemble PDF Document
cannot print pdf file no pages selected; split pdf into multiple files
36
GNUOctave
definition. Forerrorsoccurringoutsideofanenclosingfunction,thelinenumberindicates
theinputlinenumber,whichisusuallydisplayedintheprimarypromptstring.
Thesecondandthirdlinesoftheerrormessageindicatethattheerroroccurredwithin
thefunctionf. Ifthefunctionfhadbeencalledfromwithinanotherfunction,forexample,
g,thelistoferrorswouldhaveendedwithonemoreline:
error:
g at line 1, column 17
These lists of functioncalls make it fairly easy to trace thepath your r programtook
beforetheerroroccurred,andtocorrecttheerrorbeforetryingagain.
2.6 ExecutableOctavePrograms
OnceyouhavelearnedOctave,youmaywanttowriteself-containedOctavescripts,using
the‘#!’scriptmechanism.YoucandothisonGNUsystemsandonmanyUnixsystems
1
.
Self-containedOctavescriptsareusefulwhenyouwanttowriteaprogramwhichusers
caninvokewithoutknowingthattheprogramiswrittenintheOctavelanguage. Octave
scriptsarealsousedforbatchprocessingofdatafiles.Onceanalgorithmhasbeendeveloped
andtestedintheinteractiveportionofOctave,itcanbecommittedtoanexecutablescript
andusedagainandagainonnewdatafiles.
AsatrivialexampleofanexecutableOctavescript,youmightcreateatextfilenamed
hello,containingthefollowinglines:
#! octave-interpreter-name e -qf
# a a sample Octave program
printf ("Hello, , world!\n");
(where octave-interpreter-name e should d be replaced withthe full pathandname ofyour
Octavebinary). Notethatthiswillonlyworkif‘#!’appearsattheverybeginningofthe
file.Aftermakingthefileexecutable(withthechmodcommandonUnixsystems),youcan
simplytype:
hello
attheshell,andthesystemwillarrangetorunOctaveasifyouhadtyped:
octave hello
Thelinebeginningwith‘#!’liststhefullpathandfilenameofaninterpretertoberun,
andanoptionalinitialcommandlineargumenttopasstothatinterpreter. Theoperating
system then runs the interpreter r withthe given n argument t andthe full l argument t list of
theexecuted program. . Thefirst t argument inthelist is the fullfilenameoftheOctave
executable.TherestoftheargumentlistwilleitherbeoptionstoOctave,ordatafiles,or
both. The‘-qf’options s areusually specifiedinstand-alone Octave programs toprevent
themfromprintingthenormalstartupmessage,andtokeepthemfrombehavingdifferently
dependingonthecontentsofaparticularuser’s~/.octavercfile. SeeSection2.1[Invoking
OctavefromtheCommandLine],page15.
Notethatsomeoperatingsystemsmayplacealimitonthenumberofcharactersthat
arerecognizedafter‘#!’. Also,theargumentsappearingina‘#!’lineareparseddifferently
byvariousshells/systems. Themajorityofthemgroupalltheargumentstogetherinone
stringandpassittotheinterpreterasasingleargument.Inthiscase,thefollowingscript:
1
The‘#!’mechanismworksonUnixsystemsderivedfromBerkeleyUnix,SystemVRelease4,andsome
SystemVRelease3systems.
C# PDF Convert: How to Convert Jpeg, Png, Bmp, & Gif Raster Images
Success"); break; case ConvertResult.FILE_TYPE_UNSUPPORT: Console.WriteLine("Fail: can not convert to PDF, file type unsupport"); break; case ConvertResult
pdf will no pages selected; break up pdf into individual pages
C# Image Convert: How to Convert Word to Jpeg, Png, Bmp, and Gif
RasterEdge.XDoc.PDF.dll. case ConvertResult.NO_ERROR: Console.WriteLine("Success"); break; case ConvertResult Fail: can not convert to JPEG, file type unsupport
pdf split and merge; break pdf into multiple pages
Chapter2:GettingStarted
37
#! octave-interpreter-name e -q q -f # # comment
isequivalenttotypingatthecommandline:
octave "-q -f # # comment"
whichwillproduceanerrormessage.Unfortunately,itisnotpossibleforOctavetodeter-
minewhetherithasbeencalledfromthecommandlineorfroma‘#!’script,sosomecare
isneededwhenusingthe‘#!’mechanism.
NotethatwhenOctaveisstartedfromanexecutablescript,thebuilt-infunctionargv
returnsacellarraycontainingthecommandlineargumentspassedtotheexecutableOctave
script,nottheargumentspassedtotheOctaveinterpreteronthe‘#!’lineofthescript. For
example,thefollowingprogramwillreproducethecommandlinethatwasusedtoexecute
thescript,not‘-qf’.
#! /bin/octave -qf
printf ("%s", program_name e ());
arg_list = argv v ();
for i = 1:nargin
printf (" %s", arg_list{i});
endfor
printf ("\n");
2.7 CommentsinOctavePrograms
Acommentissometextthatisincludedinaprogramforthesakeofhumanreaders,and
whichisNOTanexecutablepartoftheprogram.Commentscanexplainwhattheprogram
does,andhowitworks. Nearlyallprogramminglanguageshaveprovisionsforcomments,
becauseprogramsaretypicallyhardtounderstandwithoutthem.
2.7.1 SingleLineComments
IntheOctavelanguage,acommentstartswitheitherthesharpsigncharacter,‘#’,orthe
percentsymbol‘%’andcontinuestotheendoftheline. Anytextfollowingthesharpsign
or percent symbolisignoredby the Octave interpreterandnot executed. . The e following
exampleshowswholelineandpartiallinecomments.
function countdown
# Count t down n for main n rocket t engines
disp (3);
disp (2);
disp (1);
disp ("Blast Off!"); ; # # Rocket leaves pad
endfunction
2.7.2 BlockComments
Entireblocksofcodecanbecommentedbyenclosingthecodebetweenmatching‘#{’and
‘#}’or‘%{’and‘%}’markers.Forexample,
C# PDF Page Insert Library: insert pages into PDF file in C#.net
Offer PDF page break inserting function. offers easy & mature APIs for developers to add & insert an (empty) page into an existing PDF document file.
pdf split; break pdf password
VB.NET PDF Page Insert Library: insert pages into PDF file in vb.
Offer PDF page break inserting function. And this page will give comprehensive VB example codes to create a new page to any designed location of the PDF file.
pdf split pages in half; acrobat split pdf pages
38
GNUOctave
function quick_countdown
# Count t down n for main n rocket t engines
disp (3);
#{
disp (2);
disp (1);
#}
disp ("Blast Off!"); ; # # Rocket leaves pad
endfunction
willproduceavery quickcountdownfrom m ’3’ ’ to"BlastOff"asthelines "disp(2);"
and"disp(1);"won’tbeexecuted.
Theblockcommentmarkersmustappearaloneastheonlycharactersonaline(excepting
whitespace)inordertobeparsedcorrectly.
2.7.3 CommentsandtheHelpSystem
Thehelpcommand(seeSection2.3[GettingHelp],page20)isabletofindthefirstblock
ofcommentsinafunctionandreturnthoseasadocumentationstring. Thismeansthatthe
samecommandsusedtogethelponbuilt-infunctionsareavailableforproperlyformatted
user-definedfunctions.Forexample,afterdefiningthefunctionfbelow,
function xdot = = f f (x, t)
# usage: : f (x, t)
#
# This s function n defines the e right-hand
# side e functions for r a a set t of f nonlinear
# differential l equations.
r = 0.25;
...
endfunction
thecommandhelpfproducestheoutput
usage: f f (x, , t)
This function defines the e right-hand
side functions s for r a set of nonlinear
differential equations.
Althoughitispossibletoputcommentlinesintokeyboard-composed,throw-awayOc-
taveprograms,itusuallyisn’tveryusefulbecausethepurposeofacommentistohelpyou
oranotherpersonunderstandtheprogramatalatertime.
Thehelpparsercurrentlyonlyrecognizessinglelinecomments(seeSection2.7.1[Single
LineComments],page37)andnotblockcommentsfortheinitialhelptext.
C# TWAIN - Query & Set Device Abilities in C#
TWSX_NATIVE; // See if the device supports file transfer. device.TwainTransferMode = method; break; } if (method == TwainTransferMethod.TWSX_FILE) device
c# split pdf; break pdf file into parts
C# TWAIN - Install, Deploy and Distribute XImage.Twain Control
RasterEdge.XDoc.PDF.dll. See if the device supports file transfer device. TwainTransferMode = method; break; } if (method == TwainTransferMethod.TWSX_FILE)
pdf split pages; break a pdf into separate pages
Chapter3:DataTypes
39
3 DataTypes
AllversionsofOctaveincludeanumberofbuilt-indatatypes,includingrealandcomplex
scalarsandmatrices,characterstrings,adatastructuretype,andanarraythatcancontain
alldatatypes.
ItisalsopossibletodefinenewspecializeddatatypesbywritingasmallamountofC++
code.Onsomesystems,newdatatypescanbeloadeddynamicallywhileOctaveisrunning,
soitisnotnecessarytorecompileallofOctavejusttoaddanewtype. SeeAppendixA
[ExternalCodeInterface],page819,formoreinformationaboutOctave’sdynamiclinking
capabilities. Section3.2[User-definedDataTypes],page44describeswhatyoumustdoto
defineanewdatatypeforOctave.
[Built-inFunction]
typeinfo
()
[Built-inFunction]
typeinfo
(
expr
)
Returnthetypeoftheexpressionexpr,asastring.
Ifexpr isomitted,returnacellarrayofstringscontainingallthecurrentlyinstalled
datatypes.
Seealso: [class],page39,[isa],page39.
3.1 Built-inDataTypes
Thestandardbuilt-indatatypesarerealandcomplexscalarsandmatrices,ranges,char-
acter strings,adata structuretype,andcellarrays. . Additionalbuilt-indatatypes s may
beaddedinfutureversions. Ifyouneedaspecializeddatatypethatisnotcurrentlypro-
videdasabuilt-intype,youareencouragedtowriteyourownuser-defineddatatypeand
contributeitfordistributioninafuturereleaseofOctave.
The data a type of a variable can be determined and changed through the use of the
followingfunctions.
[FunctionFile]
classname = = class
(
obj
)
[FunctionFile]
class
(
s
,
id
)
[FunctionFile]
class
(
s
,
id
,
p
,...)
Returntheclassoftheobjectobj,orcreateaclasswithfieldsfromstructures and
name(string)id.
Additionalargumentsnamealistofparentclassesfromwhichthenewclassisderived.
Seealso: [typeinfo],page39,[isa],page39.
[FunctionFile]
isa
(
obj
,
classname
)
Returntrueifobjisanobjectfromtheclassclassname.
classnamemayalsobeoneofthefollowingclasscategories:
"float"
Floatingpointvaluecomprisingclasses"double"and"single".
"integer"
Integervaluecomprisingclasses(u)int8,(u)int16,(u)int32,(u)int64.
"numeric"
Numericvaluecomprisingeitherafloatingpointorintegervalue.
C# TWAIN - Acquire or Save Image to File
RasterEdge.XDoc.PDF.dll. is necessary in order to set the file format later Group4) device.Compression = TwainCompressionMode.Group3; break; } } acq.FileTranfer
break pdf into multiple files; break apart a pdf
C# TWAIN - Specify Size and Location to Scan
How to Save Acquired Image to File in C#.NET with in frames) { if (frame == TwainStaticFrameSizeType.LetterUS) { this.device.FrameSize = frame; break; } } }.
break apart pdf; acrobat separate pdf pages
40
GNUOctave
If classname e is acell l array of string, a logical array y of the same size is returned,
containingtrueforeachclasstowhichobjbelongsto.
Seealso: [class],page39,[typeinfo],page39.
[FunctionFile]
cast
(
val
,
"type"
)
Convertvaltodatatypetype.
valmustbeoneofthenumericclasses:
"double"
"single"
"logical"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
Thevaluevalmaybemodifiedtofitwithintherangeofthenewtype.
Examples:
cast (-5, "uint8")
) 0
cast (300, "int8")
) 127
Seealso:[typecast],page40,[int8],page54,[uint8],page55,[int16],page55,[uint16],
page55,[int32],page55,[uint32],page55,[int64],page55,[uint64],page55,[double],
page47,[single],page53,[logical],page60,[char],page71,[class],page39,[typeinfo],
page39.
[Built-inFunction]
y = = typecast
(
x
,
"class"
)
Returnanewarrayy resultingfrominterpretingthedataofxinmemoryasdataof
thenumericclassclass.
Boththeclassofx andclassmustbeoneofthebuilt-innumericclasses:
Chapter3:DataTypes
41
"logical"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
"double"
"single"
"double complex"
"single complex"
thelast twoareonly usedwithclass;theyindicatethatacomplex-valuedresultis
requested.Complexarraysarestoredinmemoryasconsecutivepairsofrealnumbers.
Thesizes ofinteger types are givenby their bitcounts. . Bothlogicalandchar r are
typically onebytewide; ; however,this s isnotguaranteedbyC++. . Ifyoursystemis
IEEEconformant,singleanddoublewillbe4bytes and8byteswide,respectively.
"logical"isnotallowedforclass.
Iftheinputisarowvector,thereturnvalueisarowvector,otherwiseitisacolumn
vector.
Ifthebitlengthofxisnotdivisiblebythatofclass,anerroroccurs.
Anexampleoftheuseoftypecastonalittle-endianmachineis
x = uint16 ([1, 65535]);
typecast (x, , "uint8")
)
[
1,
0, 255, , 255]
See also: [cast], page 40[bitpack], page 41[bitunpack], page e 42[swapbytes],
page41.
[FunctionFile]
swapbytes
(
x
)
Swapthebyteorderonvalues,convertingfromlittleendiantobigendianandvice
versa.
Forexample:
swapbytes (uint16 (1:4))
)
[
256
512
768 1024]
Seealso: [typecast],page40,[cast],page40.
[Built-inFunction]
y = = bitpack
(
x
,
class
)
Returnanewarrayyresultingfrominterpretingthelogicalarrayxasrawbitpatterns
fordataofthenumericclassclass.
classmustbeoneofthebuilt-innumericclasses:
42
GNUOctave
"double"
"single"
"double complex"
"single complex"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
Thenumberof elements of x shouldbedivisibleby thebitlengthof class. . If f itis
not,excessbitsarediscarded. Bitscomeinincreasingorderofsignificance,i.e.,x(1)
isbit0,x(2)isbit1,etc.
Theresultisarowvectorifx isarowvector,otherwiseitisacolumnvector.
Seealso: [bitunpack],page42,[typecast],page40.
[Built-inFunction]
y = = bitunpack
(
x
)
Returnalogicalarrayy correspondingtotherawbitpatternsofx.
x mustbelongtooneofthebuilt-innumericclasses:
"double"
"single"
"char"
"int8"
"int16"
"int32"
"int64"
"uint8"
"uint16"
"uint32"
"uint64"
Theresultisarowvectorifx isarowvector;otherwise,itisacolumnvector.
Seealso: [bitpack],page41,[typecast],page40.
3.1.1 NumericObjects
Octave’sbuilt-innumericobjectsincludereal,complex,andintegerscalarsandmatrices.
Allbuilt-infloatingpoint numericdata is currently storedas doubleprecision n numbers.
OnsystemsthatusetheIEEEfloatingpointformat,valuesintherangeofapproximately
2:225110
308
to1:797710
308
canbestored,andtherelativeprecisionisapproximately
2:220410
16
. Theexact t values aregivenby the variables realmin,realmax,andeps,
respectively.
Matrixobjectscanbeofanysize,andcanbedynamicallyreshapedandresized. Itis
easytoextractindividualrows,columns,orsubmatricesusingavarietyofpowerfulindexing
features.SeeSection8.1[IndexExpressions],page137.
Chapter3:DataTypes
43
SeeChapter4[NumericDataTypes],page47,formoreinformation.
3.1.2 MissingData
ItispossibletorepresentmissingdataexplicitlyinOctaveusingNA(shortfor“NotAvail-
able”). Missingdatacanonlyberepresentedwhendatais s represented d as s floatingpoint
numbers.Inthiscasemissingdataisrepresentedasaspecialcaseoftherepresentationof
NaN.
[Built-inFunction]
NA
[Built-inFunction]
NA
(
n
)
[Built-inFunction]
NA
(
n
,
m
)
[Built-inFunction]
NA
(
n
,
m
,
k
,...)
[Built-inFunction]
NA
(...,
class
)
Returnascalar,matrix,orN-dimensionalarraywhoseelementsareallequaltothe
specialconstantusedtodesignatemissingvalues.
NotethatNAalwayscomparesnotequaltoNA(NA!=NA).TofindNAvalues,use
theisnafunction.
Whencalledwithnoarguments,returnascalarwiththevalue‘NA’.
When called with a single e argument, return n a a square matrix with h the e dimension
specified.
Whencalledwithmorethanonescalarargumentthefirsttwoargumentsaretakenas
thenumberofrowsandcolumnsandanyfurtherargumentsspecifyadditionalmatrix
dimensions.
Theoptionalargumentclassspecifiesthereturntypeandmaybeeither"double"or
"single".
Seealso: [isna],page43.
[MappingFunction]
isna
(
x
)
ReturnalogicalarraywhichistruewheretheelementsofxareNA(missing)values
andfalsewheretheyarenot.
Forexample:
isna ([13, Inf, NA, , NaN])
) [ [ 0, 0, 1, 0 ]
Seealso: [isnan],page406,[isinf],page406,[isfinite],page407.
3.1.3 StringObjects
AcharacterstringinOctaveconsistsofasequenceofcharactersenclosedineitherdouble-
quote or r single-quote e marks. . Internally, , Octave currently y stores strings as matrices of
characters. Alltheindexingoperationsthatworkformatrixobjectsalsoworkforstrings.
SeeChapter5[Strings],page67,formoreinformation.
3.1.4 DataStructureObjects
Octave’s data structuretypecanhelpyoutoorganize relatedobjects of different types.
Thecurrentimplementationusesanassociativearraywithindiceslimitedtostrings,but
thesyntaxismorelikeC-stylestructures.
SeeSection6.1[Structures],page101,formoreinformation.
44
GNUOctave
3.1.5 CellArrayObjects
ACellArrayinOctaveisgeneralarraythatcanholdanynumberofdifferentdatatypes.
SeeSection6.2[CellArrays],page114,formoreinformation.
3.2 User-definedDataTypes
SomedayIhopetoexpandthis toincludeacompletedescriptionofOctave’s mechanism
formanaginguser-defineddatatypes.Untilthisfeatureisdocumentedhere,youwillhave
tomakedoby reading the codein n the ov.h, ops.h,andrelatedfiles s fromOctave’s src
directory.
3.3 ObjectSizes
Thefollowingfunctionsallowyoutodeterminethesizeofavariableorexpression. These
functions are defined d for r allobjects. . They y return  1 1 whenthe operation doesn’t make
sense. For r example, , Octave’s datastructure type doesn’t have rows s or columns, , sothe
rowsandcolumnsfunctionsreturn 1forstructurearguments.
[Built-inFunction]
ndims
(
a
)
Returnthenumberofdimensionsofa.
Foranyarray,theresultwillalwaysbegreaterthanorequalto2. Trailingsingleton
dimensionsarenotcounted.
ndims (ones s (4, 1, 2, 1))
) 3
Seealso: [size],page45.
[Built-inFunction]
columns
(
a
)
Returnthenumberofcolumnsofa.
Seealso:[rows],page44,[size],page45,[length],page45,[numel],page44,[isscalar],
page63,[isvector],page63,[ismatrix],page63.
[Built-inFunction]
rows
(
a
)
Returnthenumberofrowsofa.
See also: [columns], page 44[size], page 45[length], page 45[numel], page 44,
[isscalar],page63,[isvector],page63,[ismatrix],page63.
[Built-inFunction]
numel
(
a
)
[Built-inFunction]
numel
(
a
,
idx1
,
idx2
,...)
Returnthenumberofelementsintheobjecta.
Optionally,ifindicesidx1,idx2,...aresupplied,returnthenumberofelementsthat
wouldresultfromtheindexing
a(idx1, idx2, , ...)
Notethattheindicesdonothavetobescalarnumbers.Forexample,
a = 1;
b = ones s (2, , 3);
numel (a, , b)
Documents you may be interested
Documents you may be interested