Trending March 2024 # Learn The Basic Concept Of Fopen Statement (Examples) # Suggested April 2024 # Top 10 Popular

You are reading the article Learn The Basic Concept Of Fopen Statement (Examples) updated in March 2024 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested April 2024 Learn The Basic Concept Of Fopen Statement (Examples)

Introduction to Matlab fopen

Matlab fopen statement is used for an open a file or obtains information about open files. The file handling operations like reading from file or writing on a file for these operations we need to first open a file for that fopen statement is used. We open a file in binary mode or text mode and we specify the access type like r, w, r+, a, etc. and the default access type is read. The fopen statement returns data stored in fileID1, fileID1 is a file identifier on open file.


Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

fileID1 = fopen(filename)

fileID1 = fopen(filename,permission)

fileID1 = fopen(filename,permission,machinefmt,encodingIn)

fIDs = fopen('all')

filename = fopen(fileID)

[filename,permission,machinefmt,encodingOut] = fopen(fileID)

How to Use Matlab fopen?

We use fopen statement for only open the file for these we don’t need to specify anything simply we take a fopen statement and that file name which we want to open. But in another case, if we want to write or read from file we must specify the access type in fopen statement. For these we want to specify the permission, the permission is as followed:

‘r’: The file is open for reading. And it’s a default condition.

‘r+’: The file is open for both reading as well as writing.

‘w’: It will delete the contents of an existing file or simply it creates a new file and opens it for writing.

‘w+’: It will delete the contents of an existing file or simply it creates a new file, and open it for both readings as well as writing.

‘a’: It will create and open a new file or open an existing file for writing, appending to the end of the file.

‘a+’: It will create and open a new file or open an existing file for reading and writing, appending to the end of the file.

‘A’: It will append without automatic flushing; used with tape drives

Examples to Implement Matlab fopen

Below are the examples of Matlab fopen:

Example #1

Let us see one example, in this example, we open the text file using fopen and read the data from that file. For these first we take a fopen statement, in this fopen we specify that which file we want to open that file name and the access type mode of that file, for those we take fopen in parenthesis text file name with .txt extension chúng tôi and the access type mode is read ‘r’ and these two arguments are separated by a comma. And this fopen statement we take in a file identifier that is fileID1. And then we simply read that file using a fscanf statement. And lastly, we need to close that file using a file identifier and close statement; the file close statement is fclose and files identifier of open file that is fileID1.

fileID1 = fopen(‘textfile1.txt’,’r’);formatSpec = ‘%s’;A1 = fscanf(fileID1,formatSpec)fclose(fileID1);


Example #2

Let us see an example related to the fopen statement, we already created one text file with extension .txt ‘file1.txt’ in that text file we write something information. For reading or displaying one line from that text file, we write a Matlab code, in Matlab code, we use a fopen statement fopen statement is used for an open a file or obtain information about an open file. In this example, we used fopen statement for an open a text file which we earlier created with the name ‘file1’. Then we assign a file identifier to that fopen statement. Then we use an ‘fgetl’ function it is an inbuilt function available on Matlab it used for reading one line from a file. This readied line stored in line variable and we displaying that data and then we close the file, for closing a file we take fclose in that file identifier.


tline = fgetl(fileID)fclose(fileID);

Example #3

Let us see one example related to fopen statement, in this example, we create a matrix using a magic function, the magic function is nothing but it creates a matrix of n-n number in our example it creates 4- by-4 matrix. The matrix is stored in variable A1. This matrix we want to write in a file for that we need to open that file. To open a file we use a fopen statement, fopen in parenthesis the file name in which we want to write a matrix and a type of access mode that is written ‘w’ and these we assign to the fileID1, fileID1 is a file identifier of an open file. Then we use a fprintf statement to write that matrix on a text file. Then we simply close that open file by using a file close statement and a file identifier of an open file. And for verification that the matrix is written on that text file or not we use a type function, type in parenthesis that file name in which we write a matrix.


A1 = magic(4);fileID1 = fopen (‘myfile1.txt’,’w’);nbytes1 = fprintf(fileID1,’%6d %6d %6d %6dn’,A1)fclose(fileID1);type(‘myfile1.txt’)



In this article we saw the basic concept of fopen statement, basically fopen is nothing but an open a file or obtain information about open files. We also saw the different syntax for fopen statement used in Matlab code. Also, we saw the different some examples related to fopen.

Recommended Articles

This is a guide to Matlab fopen. Here we discuss the Introduction to Matlab fopen and its Syntax along with different Examples and its Code Implementation. You can also go through our suggested articles to learn more –

You're reading Learn The Basic Concept Of Fopen Statement (Examples)

Learn The Examples Of Sql Extensions

Introduction to SQL extensions

A sql extensions is a file extension used for files containing standard query language(SQL) queries and commands to create and modify relational database objects. It is identified as .sql type. The SQL file format is written in ASCII. For the uninitiated, it can be considered a flat-file with nothing but a set of SQL statements. For example, statements for creating, inserting, extracting, updating, or deleting a data table in SQL databases. It does not contain the entire database in it.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

You must be wondering when and how we are going to use the SQL extension. The most frequent use of the .sql extension is when we have to run certain queries multiple numbers of times. Imagine writing the same query those many times. It’s terrifying right. We can instead save the query with .sql extension and open, re-run or edit it n number of times without having to rewrite the entire query again and again. Another important usage of sql extension is backing and restoring database backups. Some database servers such as SQL Server and MYSQL support this. One more prominent usage of .sql extension is exporting and sharing user-defined schemas, functions, procedures, and triggers with other users.

Examples of SQL extensions

Next, let us cover some fundamentals such as creating and opening a file with sql extension.

Example #1 – Creating a sql file extension


Having created the database, let us create a table called “cities” in it that contains a list of cities with their ids and country. Here is the create table statement for the city table.

CREATE TABLE cities ( id int NULL, country varchar (50) NULL, city varchar (50) NULL );

Now we are all set to script this create table statement using extension so that we can reuse the code. Follow the following steps for more.

Step 1: Go to object explorer

Step 2: Select the desired database

Step 3: Select the table which you want to script

Here is an image to illustrate the flow.

Once you are done with navigation, move to step 4.

Step 4: SELECT the desired statement that has to be scripted.

Step 5: Choose a file from the next menu and save the script with the desired name. Here, the file of the extension type by default. If that’s not the case for you, mention .sql as a file extension.

Example #2 – Opening a sql file extension

Opening a file of the sql extension type is as easy as creating one. You just follow the following steps.

Step 1: Go to File Menu

A dialog box as shown below will appear in front of you.

The file of the sql extension type will have the following statements. It is basically the CREATE To script for the cities table. Just run this script to create the table.

USE [Test_db] GO /****** Object:  Table [dbo].[cities]    Script Date: 07/10/2024 12:04:49 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[cities]( [id] [int] NULL, [country] [varchar](50) NULL, [city] [varchar](50) NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO

We have successfully created the table from a script (a file of sql extension type).

Example #3 – Working with .sql files

Suppose we do not have access to the Server query editor, but we want to write a query to insert a few records into the cities table. We can use text editors such as notepad, notepad++, atom, sublime, vim, etc. to view, write, or edit .sql files.

INSERT INTO [Test_db].[dbo].[cities] ([id] ,[country] ,[city]) VALUES (1,'India', 'New Delhi'), (2,'U K','London') GO

Having successfully written and saved the query in the text editor, the next task is to open the file. So open the .sql file in the server as discussed above. The query will be automatically opened in the query editor as shown below.

Now execute the query to insert records in the city table. Let us check using a SELECT statement if the data has been successfully entered.

SELECT * FROM cities;

Yes, it has been successfully populated. If you wish to re-run the same SELECT query or share it with your teammates, just save it (by pressing Ctrl + S or from the file menu). Again a dialog box as shown below will appear.

Just save it and you are good to go.


SQL extension is a file format that is used to store and save sql commands, queries, functions, triggers, etc. so that they can be reused and shared.

Recommended Articles

We hope that this EDUCBA information on “SQL extensions” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Learn The Different Examples Of Python Widgets

Introduction to Python Widgets

Widgets are small parts on web applications that allow user input. The widgets are eventful objects of Python that have a browser representation, often as control such as a slider, textbox, etc. Interactive GUIs for Python notebook are created using these Widgets. Synchronize stateless and stateful information between JavaScript Python and is done using widgets. Widget input allows us to add parameters and dashboards to the notebooks. Widget API has calls that can be given with various types of input, access bound values, and removing them. Exploration of different parameters using a single query are the results of widgets. Widgets are of many types. Few are Text, drop down, Combo box, Multi-select, which are widely used. All these widgets are quiet neat to understand and implement.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax of Widgets

import widget_name


Ipywidgets packages furnish a lot of common interface controls. These interfaces are used in exploring code and data interactively. These can be customised and assembled for creating user interfaces that are complex. Let’s see various schemes to create user interfaces using Python Ipywidgets. The package of widgets in Python can be installed in Anaconda by default. Manual installation is done with conda install Ipywidgets. Or you can also use pip install Ipywidgets, but then an extension for Jupyter Notebook is needed.

Now, getting into the actual methodology:

The block of code shows how we import the widgets. These are few widgets which are used in general.


import Ipywidgets as widgets from Ipywidgets import Hbox, Vbox import numpy as np import matplotlib.pyplot as plt from Ipython.display import display %matplotlib inline Examples of Python Widgets

Widgets have an @interact decorator, which controls the function of arguments. The f() function receives an integer as an argument. That displays a slider by default.

Example #1

Displaying a slider which has border values and can be slid along, which is an integer slider.


import Ipywidgets as wg import Ipython.display name = chúng tôi (value = ‘Name’) age = wg.IntSlider (description = ‘Age: ’) display (name, age) print (name.value + ‘ is already ‘+ str (age.value) + ‘ now ’)


The above displays an age bar or a slider, where you can slide the age of John and hold at one. It is still changeable. At age.value, you need to consider taking the value as a string as it is a number or integer, and it needs to be typecasted because all the other parameters in the command line are integers.

You can also import the FloatText widget, which is the same as above but includes a floating-point slider. Wg.FloatText() is used.

Example #2


import numpy as np %matplotlib inline From matplotlib.pyplot as plt def myPlot (c): x = np.linspace(-5,5,20) y = c * x**2  # we are going to have a parabola here. plt.plot (x, y, ‘ r-- ‘) # let us make a plot using x and y values plt.ylabel (‘ y (x) ’) # create y label and make It y (x) plt.xlabel (‘ x ‘) # x label and named it x plt.ylim([ 0, 80 ]) plt.xlim ([ -5, 5 ])

myPlot(10) #running the plot with a random value.


But our point is to see the plot change with respect to c.

For that, we include a cSlider which sides along with the possible given values and updates the plot automatically. We can give a FloatSlider as well.


c_slide = wg.FloatSlider ( value = 1.0, min = 0.5, max = 3.5, steps = 0.2 ) #Then run the function by calling myPlot and include parameters to use. wg.interact (myPlot, c = c_slide)


c_slide.key: This is the keywords which display all the different types of widgets you might want to change. This will display quiet a big list.

wg.Widgets.widget_types: This is the keyword used to displays all the types of Widgets that can be used.

Example #3


import time progress = wg.IntProgress ( description = ‘ Loading: ’ ) progress.orientation = ‘horizontal’ #we can use vertical as well. display(progress) for i in range (100) progress.value = i time.sleep (0.1)


The loading bar in the above block of code can be taken as vertical, which shows a vertical orientation.

Try typing “import this” on Python IDE; you’ll find a poem highlighting the philosophies of Python.



Demonstration of many features of packages is done by importing Ipywidgets. Widgets can be styled and customised. They can be created using JavaScript and Python Notebook – Jupyter in this case. If you remove the keyword widget in case the same cell cannot be accessed, create subsequent command. Nevertheless, a widget can be created in another cell.

Recommended Articles

This is a guide to Python Widgets. Here we discuss the introduction to Python Widgets along with the examples, respectively. You may also have a look at the following articles to learn more –

How When Statement Works In Kotlin With Examples?

Introduction to Kotlin when

Web development, programming languages, Software testing & others


In kotlin language, it has many default keywords, variables, and functions to implement the application. One of the default keywords can be used in both expression and non-expression scenarios.

val variablename; when(variablename) { —some coding logics it depends upon the requirement— } }

The above codes are the basic syntax for utilizing the when keyword on the kotlin codes. We want to write the expression based on the function’s requirement on the child function, or the inheritance concept will be implemented on the application.

Working of when statement in Kotlin

Generally, “when” is one of the keywords, and it is used in both expression and non-expression; it also checks and combined with the valid conditional statements depending on the calculation based on the user requirements, in kotlin, when it is constructed, and it can be thought of as the replacement for the switch case statement, which is similar to the other languages when the keyword is used as the expression and validating the condition like matching the values for overall expression. If condition statement, the values of the individual branches are always ignored, each branch can be of the block, and its value is the last expression of the block values.

Else loop is evaluated if none of the other branches and the condition is satisfied with the boolean condition statements; else, a loop is mandatory unless the compiler can prove that all possible cases are covered with the loop conditions. The scope of the variable is introduced with the keyword for when the subject is restricted to the body of this keyword for when expression. We can check and validate the condition using a particular type in both compile and runtime in the kotlin operators. With the help of conditional statements, the loop will use the control, and it executes the other conditions based on their needs.

Examples of Kotlin when

Below are the examples of Kotlin when:

Example #1


package one; println("Welcome To My Domain it’s a first example regarding the When keyword using the kotlin program logics") var first = 7 var second = when(first) { } println("$second") var third = when(second) { } println("Thank you users have a nice day please find your outputs $first") }


We used the above example when keywords in basic formats like int, string, string, and string formats. We can print the statements on the user console screen.

Example #2


package one; println("Welcome To My Domain it’s a second example regarding the When keyword using the kotlin program logics") var first = 'A' when(first){ } println("Thank you users have a nice day kindly try again please keep and stay with our application $first") var yrsage = 16 when(yrsage) { val numlast = 100 - yrsage println("Your marraige age is in $numlast years") } } }


Example #3


package one; enum class Third(val exampl: Boolean = false){ January(true), February, March, April(true), May, June, July(true), August, September, October, November, December(true); companion object{ fun demo(obj: Third): Boolean { } } } fun demos(th: Third) { when(th) { } } fun main(){ println("Welcome To My Domain its a third example regarding the When keyword using the kotlin program logics") for(eg in Third.values()) { println("${eg.ordinal} = ${} and is months in ${eg.exampl}") } val demo1 = Third.April; println("Thank you users your current month is ${Third.demo(demo1)}") }


In the final example, we used to calculate the current month status by using the boolean condition. We used the when keyword to print the enum class value on the function.


In the conclusion part, kotlin when is one of the conditional statements like if, else, etc. The when keyword supports non -conditional expressions also instead of the switch case statement, these statements will execute the user inputs on each step. It supports all types of user browsers, so it’s compatible when keyword satisfied with some range intervals, which depends upon the requirement.

Recommended Articles

This is a guide to Kotlin when. Here we discuss the introduction, syntax, and working of when statement in Kotlin along with the examples and outputs. You may also have a look at the following articles to learn more –

Learn The Example Of Angularjs Ng

Introduction to AngularJs ng-repeat

Web development, programming languages, Software testing & others

How Angular CLI works?

In the AngularJS framework, it is very important to know that all the In-Built directives that the AngularJS framework has provisioned will always be denoted with ng. As soon as you declare the ng-repeat directive attribute in the HTML page of your AngularJS application, the Framework knows what has to be done as it’s inbuilt the definition is defined with AngularJS framework itself. Each time ng-repeat is invoked, it initializes a template for each object from the list/collection, and each template element has its own scope.

Each object can be referred to using the local variable defined in the ng-repeat tag. The ng-repeat should be used as an attribute inside any HTML tag such as div, paragraph, table, button, href, etc. To know the index of each object in the list and keep track of it, the track by $index property can be used. Tracking by some other id parameter (not $index) which is present inside the object can also be done using track by chúng tôi Along with $index, there are few more such properties defined by AngularJS which can be used with ng-repeat, such as

$first – Will return true if the object is the first object in the List

$last – Will return true if the object is the Last object in the List

$middle – Will return true if the object is in between the List

$odd – If the value of $index is an odd number, it will return true

$even – If the value of $index is an even number, it will return true

ng-init can also be used along with the ng-repeat directive, which can help you to add an additional parameter for each object in the list ONLY for that scope of the template instance.

While using ng-repeat, something to keep a note of is that any object starting with the $ symbol will not be read by the ng-repeat directive and get ignored as its AngularJS and $ is a prefix used by AngularJS for public or private properties.



.grocery-list-class { margin-top: 20px; cursor: pointer; } .name { font-weight: bold; } .amt, .qunatity, .desc { font-weight: normal; } .amt { text-align:right; vertical-align: centre; color:blue; } h1 { text-align:center; color: orange; }

angular.module('myGroceryApp', []) .controller('GroceriesController', function($scope) { $scope.groceriesList = []; var grocery1 = {"name": "Olive Oil", "description": "The description of this oil", "amount": 154.50}; var grocery2 = {"name": "Whole Wheat Bread", "description": "The description of this Bread", "amount": 35}; var grocery3 = {"name": "Tomato Suace", "description": "The description of this Sauce", "amount": 50}; var grocery4 = {"name": "Brown Rice", "description": "The description of this Rice", "amount": 200}; var grocery5 = {"name": "Rose Water", "description": "The description of this Product", "amount": 55.75}; $scope.groceriesList.push(grocery1, grocery2, grocery3, grocery4, grocery5); });

In the above example, we are trying to display a list of groceries that have been added to the cart in tabular format on UI using the ng-repeat directive.

Make sure to include the AngularJS dependency in the Script tag so that you will be able to use the ng-repeat directive of AngularJS.

ng-repeat="grocery in groceriesList track by $index"

Here grocery is each object inside the groceries list, which is a list of all groceries in the cart. We have used a track by $index to keep track of each grocery inside the groceries list

ng-init="quantity = 1"

ng-init can be used to add any new parameter inside each grocery, and here we have added quantity to default to 1 for each grocery in the grocery list

Also, if we need to use the filter for filtering elements based on the amount or any other parameter, the filter can be used along with the ng-repeat directive and easily filter out the elements.

Just by using a few simple and easy CSS styling, we will be able to arrange the cart properly and view the contents on UI just like we want to below the output of the above code.


The ng-repeat directive in AngularJS is a very useful and one of the most widely used In-Built AngularJS directives, which are used to iterate through a list of elements and display the objects on the UI along with CSS styling, tracking by index and comes with a very little piece of code and easy to use and understand. Knowing the syntax is all that is needed, and you are ready to go. Filters can also be used with this ng-repeat directive to make it more efficient.

Recommended Articles

We hope that this EDUCBA information on “AngularJs ng-repeat” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Learn The Working And Example Of Plsql Rowtype

Introduction to PLSQL rowtype

The definition of the columns or fields retrieved from the cursor table or cursor itself in PL/SQL is done using the attribute called %ROWTYPE. Each column or record in the field is considered to have its own datatype corresponding to the type of column it is declared as. The cursor variable name or cursor name is kept at the beginning at the prefix place if the %ROWTYPE attribute. In this article. We will study the syntax, working, and implementation of rowtype attributes in PL/ SQL. In this topic, we are going to learn about PLSQL rowtype.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

As the cursor name is prefixed while making the use of the ROWTYPE attribute, the syntax of the rowtype while using it in PL/ SQL is as shown below –

cursorRecord  cursorName%ROWTYPE

In the above syntax, the terms used are as explained below –

cursorRecord – the cursorRecord is the value by which the record or field is identified.

curserName – The cursor name is the name of the cursor, which is declared explicitly in the current scope of the program.

Working of %ROWTYPE attribute

The cursor works as the pointer, which points to the individual field or record in the table. Whenever the usage of loops is done at that time, in order to refer to each of the individual records, we take the use of the sample cursor, which will store the temporary field to which we are currently referring. Thus, the complete record or the value of a single column can be pointed by the cursor.

Points to be considered

We can declare a variable in PL/ SQL as the name of the table%ROWTYPE datatype can prove very much helpful for data transferring between PL/SQL and tables of the database. The most important point here is that we can make the use of a single variable instead of multiple separate variables for each column of the database.

We don’t even need to have any idea regarding each of the columns of the table because instead of using the made-up variable names for each of the columns, we will be referring to each of the columns by using its real name. Thus, even if any of the changes are made in the structure of the table later on, which involves the addition and deletion of the columns from it, there will be no necessity to make any changes in the program or code that we have written.

We can refer to each of the individual fields of the record by making the use of dot symbol in the format name of the record. name of the field. Using this format, we can read and write one field at a time.

In order to assign all the fields value at once, we can make the use of one of the two mentioned methods below –

Aggregate assignment of all the records can be done in PL/ SQL in case if they refer to the same cursor or table.

SELECT or FETCH statements can be used to assign the list of values to a particular record. The order in which the names of the column are declared should be the same as they appear in the command. The selected and fetched items should have simple names, or if in case they are, expressions must have aliases if they are associated with %ROWTYPE.

Example of PLSQL rowtype Example #1 SELECT * FROM [customers_details];

The output of the execution of the above query statement is as shown below, showing the contents of the table customer details –

To retrieve the details of the table in such a way that each of the customer’s first name is retrieved and the contact details showing its mobile number is retrieved, we can create a procedure in PL/ SQL. In this procedure, we will make use of the cursor named sample cursor, which will point out all the resultset of the customer details table having its f_name and mobile number fields.

Further, we will loop through the result by rotating it in the loop where we will take each of the individual records of the cursor table contents one by one in a variable named sample variable. Then we will keep displaying the result in such a way that the DBMS output will contain the name and its corresponding mobile number with an in-between string attached as “having the mobile number”.

CREATE OR REPLACE PROCEDURE 2 IS CURSOR sampleCursor IS SELECT f_name, mobile_number FROM customers_details sampleVariable sampleCursor%ROWTYPE; BEGIN OPEN sampleCursor; LOOP FETCH sampleCursor INTO sampleVariable; EXIT WHEN sampleCursor%NOTFOUND; || sampleVariable.mobile_number ); END LOOP; CLOSE sampleCursor; END;

The output of the above code is as displayed below –

Example #2

Consider one more example where we have a table named Employees, which has the following contents in it when retrieved by using the query statement –

SELECT * FROM [Employees]

The execution of the above instruction gives the following output –

Now, in case if we want to retrieve all the data of the Employees table in such a way that it should display the first name and then the birth date in the format – firstname has his birthday on birthdate. For that thing, we can make the use of the following procedure –

CREATE OR REPLACE PROCEDURE 2 IS CURSOR sampleCursor IS SELECT FirstName, BirthDate FROM Employees sampleVariable sampleCursor%ROWTYPE; BEGIN OPEN sampleCursor; LOOP FETCH sampleCursor INTO sampleVariable; EXIT WHEN sampleCursor%NOTFOUND; || sampleVariable.BirthDate ); END LOOP; CLOSE sampleCursor; END;

The output of the above procedure is as shown below –


The use of the %ROWTYPE attribute in PL/ SQL is mostly used for referring and having a cursor pointer to the records, which can be columns of the particular table or even the complete fields record itself.

Recommended Articles

We hope that this EDUCBA information on “PLSQL rowtype” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about Learn The Basic Concept Of Fopen Statement (Examples) on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!