Difference between revisions of "Scilab/C4/User-Defined-Input-and-Output/English"
Line 25: | Line 25: | ||
* '''load''' function | * '''load''' function | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide | ||
+ | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| System Requirements | ||
+ | |||
+ | For Demonstration: Ubuntu Linux12.04 operating system is used with Scilab version 5.3.3 installed | ||
Line 34: | Line 39: | ||
# Basic knowledge of '''Scilab'''. | # Basic knowledge of '''Scilab'''. | ||
− | # If not, for relevant tutorials please visit '''spoken hyphen tutorial dot org''' | + | # If not, for relevant spoken tutorials please visit '''spoken hyphen tutorial dot org''' |
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
Line 51: | Line 51: | ||
* is used to take the input from the user. | * is used to take the input from the user. | ||
− | * provides a prompt in the text string for user input. | + | *It provides a prompt in the text string for user input. |
− | * waits for input from the keyboard. | + | * It waits for input from the keyboard. |
If nothing but a carriage return is entered at the prompt, '''input()''' function returns an empty matrix. | If nothing but a carriage return is entered at the prompt, '''input()''' function returns an empty matrix. | ||
Line 58: | Line 58: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| Slide | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The '''input''' function can be written in two ways | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| The '''input''' function can be written in two ways . |
− | + | First ,x= input(''message to display'') | |
− | + | Second,x= input("message to display","strings") | |
In the second example, the second argument is “'''string'''”. | In the second example, the second argument is “'''string'''”. | ||
Line 73: | Line 73: | ||
--> y = input (“ Enter your age”, “string”) | --> y = input (“ Enter your age”, “string”) | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"|Switch to the''' Scilab Console''' window and type, |
+ | |||
+ | '''-->x is equal to input open bracket inside double quotes Enter your age close the double quotes close the bracket''' and press enter.Type 25 and press enter | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Now type | Now type | ||
− | '''-->y is equal to input | + | '''-->y is equal to input into bracket into double quotes Enter your age close the double quotes comma again inside double quotes write string close the bracket.''' and press enter |
− | + | type 25 and press enter | |
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We see that in both the cases the input we entered, was a number 25. | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| We see that in both the cases the input we entered through a keyboard, was a number 25. |
|- | |- | ||
Line 110: | Line 97: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Now, let us check the type of variable that '''x''' and '''y''' are. | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Now, let us check the type of variable that '''x''' and '''y''' are. | ||
− | + | Let us clear the console using the clc command. | |
We are doing this to validate the use and importance of the argument “string”, given in the second example. | We are doing this to validate the use and importance of the argument “string”, given in the second example. | ||
Line 121: | Line 108: | ||
− | '''-->typeof(x)''' | + | '''-->typeof(x)'''and press enter |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | similarly; | |
− | ''' | + | '''-->typeof(y)''' and press enter |
− | |||
|- | |- | ||
Line 160: | Line 141: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.097cm;"| | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us see an example for this. | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Let us see an example for this.Switch to the console |
− | |||
|- | |- | ||
Line 174: | Line 154: | ||
'''is taken as a STRING''' | '''is taken as a STRING''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| '''-->mprintf | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.097cm;"| Type'''-->mprintf into bracket into double quotes type iteration to percentage i result is colon slash n alpha equal to percentf comma 335 close the bracket 0.535 the message will be displayed as a CONSTANT comma while value of y is equal to percentage s is taken as a STRING close double quotes comma x comma y close the bracket''' |
Revision as of 17:47, 17 April 2013
Title of script: User defined Input/output in Scilab
Author: Anuradha Amrutkar
Keywords: input, mprintf, save() , load()
Visual Cue | Narration |
---|---|
Slide | Welcome to this spoken tutorial on User-defined Input and Output using Scilab. |
Slide | In this tutorial, we will learn
|
Slide | System Requirements
For Demonstration: Ubuntu Linux12.04 operating system is used with Scilab version 5.3.3 installed
|
Slide | Pre-requisites:
You should have
|
Slide | Input Function:
The input() function
If nothing but a carriage return is entered at the prompt, input() function returns an empty matrix. |
Slide | The input function can be written in two ways .
First ,x= input(message to display) Second,x= input("message to display","strings") In the second example, the second argument is “string”.
|
Scilab Console
--> x = input (“ Enter your age”)
|
Switch to the Scilab Console window and type,
-->x is equal to input open bracket inside double quotes Enter your age close the double quotes close the bracket and press enter.Type 25 and press enter
-->y is equal to input into bracket into double quotes Enter your age close the double quotes comma again inside double quotes write string close the bracket. and press enter
|
We see that in both the cases the input we entered through a keyboard, was a number 25. | |
Now, let us check the type of variable that x and y are.
Let us clear the console using the clc command. We are doing this to validate the use and importance of the argument “string”, given in the second example. | |
-->typeof(x)
|
To check the type of variable, let us type
-->typeof(y) and press enter
|
You can see it yourself, that
| |
Slide | Let us now see how to format the output that is displayed on the console.
|
Let us see an example for this.Switch to the console
| |
Scilab console
-->mprintf("Value of x=%d is taken as a CONSTANT, while value of y=%s is taken as a STRING", x , y)
is taken as a STRING |
Type-->mprintf into bracket into double quotes type iteration to percentage i result is colon slash n alpha equal to percentf comma 335 close the bracket 0.535 the message will be displayed as a CONSTANT comma while value of y is equal to percentage s is taken as a STRING close double quotes comma x comma y close the bracket
|
Slide | Now, let us discuss the use of save and load command.
tion and continue at a later stage type
called thissession.
and the computation can be resumed where you left off.
|
Slide | * save(filename) saves all current variables in the file defined by filename.
|
Scilab Console
a =
0. 1. --> b = ones (a) b =
1. 1. --> save('matrix-a-b.dat', a, b) |
Let us see an example to illustrate the save and load commands usage.
Let us define two matrices say a and b
or it can also be written as -->save('matrix-a-b.dat',a,b)
|
Scilab Console
|
Now let us load the file back in to the variables.
Before this, let us clear the variables a and b
!--error 4 Undefined variable: a
!--error 4 Undefined variable: b |
Scilab Console
|
Now let us load back the values from the binary files in these variables a and b using the load command.
|
--> a
a = 1. 0. 0. 1.
b =
1. 1. |
Let us check the values in variables a and b
|
Summary | Let us summarize what we learnt -
|
Slide | Watch the video available at the link shown below
It summarises the Spoken Tutorial project If you do not have good bandwidth, you can download and watch it |
Spoken Tutorial Workshops | The Spoken Tutorial Project Team
Conducts workshops using spoken tutorials Gives certificates to those who pass an online test For more details, please write to |
Acknowledgement | Spoken Tutorial Project is a part of the Talk to a
Teacher project It is supported by the National Mission on Education through ICT, MHRD, Government of India More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro |
This is Anuradha Amrutkar from IIT Bombay
Thank You for joining |