CSE 123. Lecture 9. Formatted. Input/Output Operations
|
|
- Elisabeth Bridges
- 6 years ago
- Views:
Transcription
1 CSE 123 Lecture 9 Formatted Input/Output Operations
2 fpintf function writes formatted data in a user specified format to a file fid fprintf Function Format effects only the display of variables not their values through program execution fprintf(fid,format,val1,val2,.) :the file id to which data will be written (no fid for printing on CW) format :the format string. % always marks the beginning of a format The structure of a format specifier %-12.5e Marker Modifier Field Width Precision Format Descriptor (Required) (Optional) (Optional) (Optional) (Required)
3 Common format specifier notation for fprintf Specifier %c Single character %d Decimal notation (signed) %e Exponential notation %E Exponential notation %f Fixed-point notation Description %g The more compact of %e and %f. Insignificant zeros do not print %s String of characters %u Decimal notation unsigned
4 Escape characters in Format strings symbol \n New line \t Horizontal tab \b backspace \\b Print an ordinary backslash (\)( Description \ or Print an aposthrophe or single quote %% Print an ordinary percent symbol (%)
5 Example: Decimal (integer) data is displayed using %d format specifier. fprintf( %d %d\n,123) fprintf( %6d %6d\n,123) fprintf( %6.4d %6.4d\n,123) If a non decimal number is displayed with the %d specifier, the specifier will be ignored and the number will be displayed in exponential format fprintf( %6d\n,123.4) produces e+002
6 Example: floating point (real) data is displayed using %e, %f and %g format specifiers fprintf( %f %f\n,123.4) (default is 6 chars after the decimal place) fprintf( %8.2f %8.2f\n,123.4) fprintf( %4.2f %4.2f\n,123.4) (6 chars wide field) fprintf( %10.2e %10.2e\n,123.4) e+002 fprintf( %10.2E %10.2E\n,123.4) E+002 fprintf('%8.4f\n',123.4) n',123.4) fprintf('%8.4g\n',123.4) n',123.4)
7 Example: character data may be displayed with %c or %s format specifiers. fprintf( %c %c\n, s ) s fprintf( %s %s\n, string ) string fprintf( %8s %8s\n, string ) string fprintf( %-8s 8s\n, string ) String (left justified)
8 Examples: x = 0:.1:1; y = [x; exp(x)]; %fid = fopen('exp.txt', 'wt'); fprintf(fid, '%6.2f %12.8f\n', y); %fclose(fid) fprintf(... 'A unit circle has circumference %g radians.\n', 2*pi) A unit circle has circumference radians. B = [ ; ] fprintf(1, 'X is %6.2f meters or %8.3f mm\n', 9.9, 9900, B) X is 9.90 meters or mm X is 8.80 meters or mm X is 7.70 meters or mm
9 Data Import-Export Why is it important? Lab experiment results are: usually recorded in lab (even on paper) Put together and stored into a data file Analyzed using mathematical tools Text file (.txt) Microsoft Excel file (.xls) Binary file What do we want to export? Save everything in the workspace for post analysis. Save a selected number of results from the analysis in a text file (formatted or not)
10 Importing data Two common ways Direct input through the keyboard (using the input function) Good for individual input. Not so good for large amount of data. Use existing data stored in a file and import them into Matlab. Good for any data set size. Need to know the format of the data.
11 Different types of data files Importing data Text based files = formatted data for user usage. (.txt.dat ) Usually follows the American Standard Code for Information Interchange (ASCII) Binary files = Pre-converted data for computer usage. (.bin.mat) Software specific format = formatted data for software usage (.xls) Depending on the type of data file Different import function
12 Function load Syntax: load filename Importing data load filename loads all the variables from filename If filename has an extension other than.mat, load treats the file as ASCII data. If filename has no extension, load looks for file named filename or filename.mat and treats it as a binary MAT-file. test1.txt >> load test1.txt; >> whos Name Size Bytes Class test1 11x2 176 double array
13 Importing data Function dlmread test2.txt 7.2;8.5;6.2; ;9.2;8.1;7.2 Syntax: A = dlmread('filename', 'delimiter'); test3.txt dlmread command works even if the contents of filename has spaces: 7.2; 8.5; 6.2; ; 9.2; 8.1; 7.2 >> A=dlmread('test2.txt',';') A =
14 Importing data Function textread Syntax: [A,B,C,...] = textread('filename','format') [A,B,C,...] = textread('filename','format',n) [A,B,C,...] = textread('filename','format') reads data from the file filename into the variables A,B,C, and so on, using the specified format, until the entire file is read. textread is useful for reading text files with known mixed formats. Both fixed and free format files can be handled. The format needs to be specified with a specifier like fprintf %s for string, %f for fix point notation %u for integers [A,B,C,...] = textread('filename','format',n) reads data from the file 'filename' N times.
15 Importing data test4.txt Ann Type Yes Joe Type No >> [A B C D E]=textread('test4.txt',' %s %s %f %f %s') A = 'Ann' 'Joe' B = 'Type1' 'Type2' C = D = E = 'Yes' 'No' >> [A B C D E]=textread('test4.txt',' %s %s %f %f %s',1) A = 'Ann' B = 'Type1' C = D = 45 E = 'Yes'
16 Importing data Function fscanf : Read formatted data from file Syntax: A = fscanf(fid, format) [A,count] = fscanf(fid, format, size) A = fscanf(fid, format) reads data from the file specified by fid, converts it according to the specified format string, and returns it in matrix A. Argument fid is an integer file identifier obtained from fopen. format is a string specifying the format of the data to be read. [A,count] = fscanf(fid, format, size) reads the amount of data specified by size, converts it according to the specified format string, and returns it along with a count of values successfully read. size is an argument that determines how much data is read. Options n inf [m,n] Read at most n numbers, characters, or strings. Read to the end of the file. Read at most (m*n) numbers, characters, or strings. Fill a matrix of at most m rows in column order. n can be inf, but m cannot.
17 Importing data Example 1: fid = fopen('exp.txt', 'r'); a = fscanf(fid, '%g %g', [2 inf]) % It has two rows now. a = a'; fclose(fid) xdata.txt Example 2: clc;clear; fileid=fopen( xdata.txt', 'r' ); [a,nvals]=fscanf( fileid,'%d ',inf); fclose( fileid); a nvals a = nvals =
18 Importing data Data Format Sample File Extension Matlab function txt.dat or other load 1; 2; 3; 4; 5 6; 7; 8; 9; 10 or 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Ann Type Yes Joe Type No Grade1 Grade2 Grade txt.dat.csv or other.txt.dat or other.txt.dat or other dlmread or csvread textread or fscanf textread or fscanf
19 Tips for loading data Set up the PATH Syntax: path(path,'newpath') View or change the MATLAB directory search path path(path,'c:/temp'); path(path, z:/me102');
20 Tips for loading data Use for loops to load entire series of files for j=1:n name1= test00'; name2=num2str(j); name3=.txt ; end NAME=[name1 name2 name3]; F=load(NAME); A(:,1)= F(:,1); A(:,j+1)= F(:,2); test001.txt 0 0 test002.txt test003.txt
21 Exporting data Function save Syntax: save filename save filename stores all the workspace variables in filename.mat in the current directory Selected variables can be saved: save filename A B C stores the variables A B and C current directory in filename.mat in the
22 Exporting data Three Steps: Functions fopen, fprintf and fclose 1 fopen: opens a file or obtain information about open files Syntax: fid = fopen(filename,permission) permission= 'r 'w 'a Open file for reading (default). Open file, or create new file, for writing; discard existing contents, if any. Open file, or create new file, for writing; append data to the end of the file.
23 Exporting data fopen file permissions r Open an existing file for reading only r+ r+ Open an existing file for reading and writing w w+ w+ a a+ a+ Delete the contents of an existing file (or( create a new file) and open it for writing only. Delete the contents of an existing file (or( create a new file) and open it for reading and writing Open an existing file (or( create a new file) and open it for writing only, appending to the end of file. Open an existing file (or( create a new file) and open it for reading and writing, appending to the end of file.
24 Functions fopen,fprintf and fclose Exporting data 2 fprintf: Used the same way as display function, except that this time, the formatting of the data is retained in the data file. Syntax: fprintf(fid,format,a,...) Formats the data in the real part of matrix A (and in any additional matrix arguments) under control of the specified format string, and writes it to the file associated with file identifier fid. 3 fclose: close one or more open files Syntax: fclose(fid)
25 Functions fopen, fprintf and fclose Exporting data x = 0:0.1:1; Y = [x; exp(x)]; fid = fopen('exp.txt','w'); fprintf(fid,'%6.2f %12.8f \n',y); fclose(fid) File created in current directory Exp.txt
26 Importing data (more ) Function csvread Syntax: M = csvread(filename) M = csvread(filename, row, col) M = csvread(filename, row, col, range) M = csvread(filename) reads a comma-separated value formatted file, filename. The filename input is a string enclosed in single quotes. The result is returned in M. The file can only contain numeric values. M = csvread(filename, row, col) reads data from the comma-separated value formatted file starting at the specified row and column. The row and column arguments are zero based, so that row=0 and col=0 specify the first value in the file. M = csvread(filename, row, col, range) reads only the range specified. Specify range using the notation [R1 C1 R2 C2] where (R1,C1) is the upper left corner of the data to be read and (R2,C2) is the lower right corner. You can also specify the range using spreadsheet notation, as in range = 'A1..B7'.
27 Importing data (more ) Example: csvread csvread('csvlist.dat') ans = csvlist.dat 02, 04, 06, 08, 10, 12 03, 06, 09, 12, 15, 18 05, 10, 15, 20, 25, 30 07, 14, 21, 28, 35, 42 11, 22, 33, 44, 55, 66
28 Importing data (more ) Example: csvread To read the matrix starting with zero-based row 2, column 0, and assign it to the variable m, m = csvread('csvlist.dat', 2, 0) m =
29 Importing data (more ) Example: csvread To read the matrix bounded by zero-based (2,0) and (3,3) and assign it to m, m = csvread('csvlist.dat', 2, 0, [2,0,3,3]) m =
30 Exporting data (more ) Function csvwrite Syntax: csvwrite(filename,m) csvwrite(filename,m,row,col) csvwrite(filename,m) writes matrix M into filename as comma-separated values. The filename input is a string enclosed in single quotes. csvwrite(filename,m,row,col) writes matrix M into filename starting at the specified row and column offset. The row and column arguments are zero based, so that row=0 and C=0 specify the first value in the file.
31 Exporting data (more ) Example: csvwrite m = [ ; ; ; ]; csvwrite('csvlist.dat',m) type csvlist.dat 3,6,9,12,15 5,10,15,20,25 7,14,21,28,35 11,22,33,44,55
32 Exporting data (more ) Example: csvwrite m = [ ; ; ; ]; csvwrite('csvlist.dat',m,0,2) type csvlist.dat,,3,6,9,12,15,,5,10,15,20,25,,7,14,21,28,35,,11,22,33,44,55
33 Importing data (more ) Function xlsread reads MS Excel files Syntax: num = xlsread(filename) num = xlsread(filename, -1) num = xlsread(filename, sheet, 'range ) num = xlsread(filename) returns numeric data in double array num from the first sheet in the Microsoft Excel spreadsheet file named filename. The filename argument is a string enclosed in single quotes. num = xlsread(filename, -1) opens the file filename in an Excel window, enabling you to interactively select the worksheet to be read and the range of data on that worksheet to import. num = xlsread(filename, sheet, 'range') reads data from a specific rectangular region (range) of the worksheet specified by sheet.
34 Importing data (more ) Example: xlsread A = xlsread('testdata1.xls') A = testdata1.xls
35 Importing data (more ) Example: xlsread A = xlsread('testdata1.xls,-1) A = testdata1.xls
36 Importing data (more ) Example: xlsread A = xlsread('testdata1.xls,1, A4:B5 ) A = testdata1.xls
37 Exporting data (more ) Function xlswrite Syntax: xlswrite(filename, M) xlswrite(filename, M, sheet, 'range') xlswrite(filename, M) writes matrix M to the Excel file filename. The filename input is a string enclosed in single quotes. The input matrix M is an m-by-n numeric, character, or cell array, where m < and n < 256. The matrix data is written to the first worksheet in the file, starting at cell A1. xlswrite(filename, M, sheet, 'range') writes matrix M to a rectangular region specified by range in worksheet sheet of the file filename.
38 Exporting data (more ) Example: xlswrite xlswrite('testdata', [ ]) d = {'Time', 'Temp'; 12 98; 13 99; 14 97}; s = xlswrite('tempdata.xls', d, 'Temperatures', 'E1') tempdata.xls Time Temp
ES 117. Formatted Input/Output Operations
ES 117 Formatted Input/Output Operations fpintf function writes formatted data in a user specified format to a file fid fprintf Function Format effects only the display of variables not their values through
More informationUsing files. Computer Programming for Engineers (2014 Spring)
Computer Programming for Engineers (2014 Spring) Using files Hyoungshick Kim Department of Computer Science and Engineering College of Information and Communication Engineering Sungkyunkwan University
More informationAccess to Delimited Text Files
Access to Delimited Text Files dlmread(filename, delimiter) reads ASCII-delimited file of numeric data. dlmwrite(filename, M, delimiter) writes the array M to the file using the specified delimiter to
More informationPROGRAMMING WITH MATLAB WEEK 13
PROGRAMMING WITH MATLAB WEEK 13 FILE INPUT AND OUTPUT Input statements read in values from the default or standard input device. In most systems the default input device is the keyboard. The input expression
More informationImporting and Exporting Data
Class14 Importing and Exporting Data MATLAB is often used for analyzing data that was recorded in experiments or generated by other computer programs. Likewise, data that is produced by MATLAB sometimes
More informationBeyond the Mouse A Short Course on Programming
1 / 14 Beyond the Mouse A Short Course on Programming 5. Matlab IO: Getting data in and out of Matlab Ronni Grapenthin and Glenn Thompson Geophysical Institute, University of Alaska Fairbanks October 10,
More information1 >> Lecture 6 2 >> 3 >> -- User-Controlled Input and Output 4 >> Zheng-Liang Lu 367 / 400
1 >> Lecture 6 2 >> 3 >> -- User-Controlled Input and Output 4 >> Zheng-Liang Lu 367 / 400 American Standard Code for Information Interchange (ASCII) 2 Everything in the computer is encoded in binary.
More informationSingular Value Decomposition (SVD) 1
Singular Value Decomposition (SVD) 1 Let A m n be a matrix. Then σ is called one singular value associated with the singular vectors u R m 1 and v R n 1 for A provided that { Av = σu, A T u = σv. We further
More information5. MATLAB I/O 1. Beyond the Mouse GEOS 436/636 Jeff Freymueller, Sep 26, The Uncomfortable Truths Well, hop://xkcd.com/568 (April 13, 2009)
5. MATLAB I/O 1 Beyond the Mouse GEOS 436/636 Jeff Freymueller, Sep 26, 2017 The Uncomfortable Truths Well, hop://xkcd.com/568 (April 13, 2009) Topics Loading and Saving the Workspace File Access Plo$ng
More informationChapter 11 Input/Output (I/O) Functions
EGR115 Introduction to Computing for Engineers Input/Output (I/O) Functions from: S.J. Chapman, MATLAB Programming for Engineers, 5 th Ed. 2016 Cengage Learning Topics Introduction: MATLAB I/O 11.1 The
More informationLow-Level File I/O. 1. Open a file. 2. Read or write data into the file. 3. Close the file. Zheng-Liang Lu 1 / 14
Low-Level File I/O Low-level file I/O functions allow the most control over reading or writing data to a file. However, these functions require that you specify more detailed information about your file
More informationFö 6: Filhantering. DN1212 Numeriska metoder och grundläggande programmering. Pawel Herman. KTH/CB
Fö 6: Filhantering DN1212 Numeriska metoder och grundläggande programmering paherman@kth.se KTH/CB 22 februari Pawel 2013Herman Lecture outline Recapitulation of what we already know about I/O Matlab format
More informationMATLAB User-defined functions, Data Input/Output. Edited by Péter Vass
MATLAB User-defined functions, Data Input/Output Edited by Péter Vass User-defined functions Although, MATLAB provides a wide range of built-in functions it may often be necessary to create and use an
More informationENG Introduction to Engineering
GoBack ENG 100 - Introduction to Engineering Lecture # 9 Files, Sounds, Images and Movies Koç University ENG 100 - Slide #1 File Handling MATLAB has two general ways of importing/exporting data from the
More informationWorking with Excel Files. a = round(rand(5,3)*100) xlswrite('rand.xlsx',a) b = xlsread('rand.xlsx')
File I/O Working with Excel Files a = round(rand(5,3)*100) xlswrite('rand.xlsx',a) b = xlsread('rand.xlsx') Excel files with mixed content >> [nums, txt, raw] = xlsread('texttest.xls') nums = 123 333 432
More informationMatlab Input/Output. Goal of this section Learn user-controlled Input Output Read/write data files (optional) Input/output 5-
Matlab Input/Output Goal of this section Learn user-controlled Input Output Read/write data files (optional) 85-232 Input/output 5-1 Input: initialization >> a=[-1 0 0 ; 1 1 0] >> b=[1, 2, 3; 2:4] >> b=[1,
More informationScalars and Variables
Chapter 2 Scalars and Variables In this chapter, we will discuss arithmetic operations with scalars (numbers, really an array with only one element) and variables. Scalars can be used directly in calculations
More informationLecture 5: Strings, Printing, and File I/O
1 Lecture 5: Strings, Printing, and File I/O 1 Learning objectives At the of this class you should be able to... be able to name the three Matlab data types most commonly used in ME 352 be able to use
More informationMatlab Programming Arrays and Scripts 1 2
Matlab Programming Arrays and Scripts 1 2 Mili I. Shah September 10, 2009 1 Matlab, An Introduction with Applications, 2 nd ed. by Amos Gilat 2 Matlab Guide, 2 nd ed. by D. J. Higham and N. J. Higham Matrix
More information12-Reading Data text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie
12-Reading Data text: Chapter 4.4-4.5 ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie Overview Reading Data from.txt Reading Data from.xls and.csv Reading Data from.mat User Interface
More informationLecture 7. MATLAB and Numerical Analysis (4)
Lecture 7 MATLAB and Numerical Analysis (4) Topics for the last 2 weeks (Based on your feedback) PDEs How to email results (after FFT Analysis (1D/2D) Advanced Read/Write Solve more problems Plotting3Dscatter
More informationMATLAB Introduction to MATLAB Programming
MATLAB Introduction to MATLAB Programming MATLAB Scripts So far we have typed all the commands in the Command Window which were executed when we hit Enter. Although every MATLAB command can be executed
More informationMATLAB. Data and File Management
MATLAB Data and File Management File Details Storage of data in variables and arrays is temporary. For permanent retention of data files are used. All of us are familiar with files. We save our work (e.g.
More informationProgramming in Mathematics. Mili I. Shah
Programming in Mathematics Mili I. Shah Starting Matlab Go to http://www.loyola.edu/moresoftware/ and login with your Loyola name and password... Matlab has eight main windows: Command Window Figure Window
More informationQuick MATLAB Syntax Guide
Quick MATLAB Syntax Guide Some useful things, not everything if-statement Structure: if (a = = = ~=
More informationSTAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006
STAT 39 Handout Making Plots with Matlab Mar 26, 26 c Marina Meilă & Lei Xu mmp@cs.washington.edu This is intended to help you mainly with the graphics in the homework. Matlab is a matrix oriented mathematics
More informationCopyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented
More information13-Writing Data text: Chapter ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie
13-Writing Data text: Chapter 4.4-4.5 ECEGR 101 Engineering Problem Solving with Matlab Professor Henry Louie Overview Writing Data to.txt Writing Data to.xls and.csv Writing Data to.mat Dr. Henry Louie
More informationCMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program
CMPT 102 Introduction to Scientific Computer Programming Input and Output Janice Regan, CMPT 102, Sept. 2006 0 Your first program /* My first C program */ /* make the computer print the string Hello world
More informationProgramming in MATLAB
2. Scripts, Input/Output and if Faculty of mathematics, physics and informatics Comenius University in Bratislava October 7th, 2015 Scripts Scripts script is basically just a sequence of commands the same
More informationWorksheet 6. Input and Output
Worksheet 6. Input and Output Most programs (except those that run other programs) contain input or output. Both fortran and matlab can read and write binary files, but we will stick to ascii. It is worth
More informationChapters covered for the final
Chapters covered for the final Chapter 1 (About MATLAB) Chapter 2 (MATLAB environment) Chapter 3 (Built in Functions):3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.8, 3.9 Chapter 4 (Manipulating Arrays):4.1,4.2, 4.3
More informationAn Introductory Tutorial on Matlab
1. Starting Matlab An Introductory Tutorial on Matlab We follow the default layout of Matlab. The Command Window is used to enter MATLAB functions at the command line prompt >>. The Command History Window
More informationAppendix A. Introduction to MATLAB. A.1 What Is MATLAB?
Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system
More informationUsing the fprintf command to save output to a file.
Using the fprintf command to save output to a file. In addition to displaying output in the Command Window, the fprintf command can be used for writing the output to a file when it is necessary to save
More informationChapter 2. MATLAB Basis
Chapter MATLAB Basis Learning Objectives:. Write simple program modules to implement single numerical methods and algorithms. Use variables, operators, and control structures to implement simple sequential
More informationOUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.
1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN
More informationBasic Plotting. All plotting commands have similar interface: Most commonly used plotting commands include the following.
2D PLOTTING Basic Plotting All plotting commands have similar interface: y-coordinates: plot(y) x- and y-coordinates: plot(x,y) Most commonly used plotting commands include the following. plot: Draw a
More informationChapter 3: Functions and Files
Topics Covered: Chapter 3: Functions and Files Built-In Functions Mathematical Functions User-Defined Functions Function Files Anonymous Functions Function Functions Function Handles Working with Data
More information12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.
Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.
More informationPART 2 DEVELOPING M-FILES
PART 2 DEVELOPING M-FILES Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 17 September 2018 Topic Outcomes Week Topic Topic Outcomes 6-8 Creating
More informationThere is also a more in-depth GUI called the Curve Fitting Toolbox. To run this toolbox, type the command
Matlab bootcamp Class 4 Written by Kyla Drushka More on curve fitting: GUIs Thanks to Anna (I think!) for showing me this. A very simple way to fit a function to your data is to use the Basic Fitting GUI.
More informationAWK - PRETTY PRINTING
AWK - PRETTY PRINTING http://www.tutorialspoint.com/awk/awk_pretty_printing.htm Copyright tutorialspoint.com So far we have used AWK's print and printf functions to display data on standard output. But
More informationChapter 3: Programming with MATLAB
Chapter 3: Programming with MATLAB Choi Hae Jin Chapter Objectives q Learning how to create well-documented M-files in the edit window and invoke them from the command window. q Understanding how script
More informationSBT 645 Introduction to Scientific Computing in Sports Science #6
SBT 645 Introduction to Scientific Computing in Sports Science #6 SERDAR ARITAN serdar.aritan@hacettepe.edu.tr Biyomekanik Araştırma Grubu www.biomech.hacettepe.edu.tr Spor Bilimleri Fakültesi www.sbt.hacettepe.edu.tr
More informationCME 192: Introduction to Matlab
CME 192: Introduction to Matlab Matlab Basics Brett Naul January 15, 2015 Recap Using the command window interactively Variables: Assignment, Identifier rules, Workspace, command who and whos Setting the
More informationToday. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed
CS 150 Introduction to Computer Science I Data Types Today Last we covered o main function o cout object o How data that is used by a program can be declared and stored Today we will o Investigate the
More informationProgramming in MATLAB
trevor.spiteri@um.edu.mt http://staff.um.edu.mt/trevor.spiteri Department of Communications and Computer Engineering Faculty of Information and Communication Technology University of Malta 17 February,
More informationChapter 9. Above: An early computer input/output device on the IBM 7030 (STRETCH)
Chapter 9 Above: An early computer input/output device on the IBM 7030 (STRETCH) http://computer-history.info/page4.dir/pages/ibm.7030.stretch.dir/ Io One of the moon s of Jupiter (A Galilean satellite)
More informationProgramming and Data Structures
Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()
More informationINTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from
INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 printf and scanf Streams (input and output)
More informationSECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing
SECTION 1: INTRODUCTION ENGR 112 Introduction to Engineering Computing 2 Course Overview What is Programming? 3 Programming The implementation of algorithms in a particular computer programming language
More informationSpring 2010 Instructor: Michele Merler.
Spring 2010 Instructor: Michele Merler http://www1.cs.columbia.edu/~mmerler/comsw3101-2.html Type from command line: matlab -nodisplay r command Tells MATLAB not to initialize the visual interface NOTE:
More informationThe Design of C: A Rational Reconstruction (cont.)
The Design of C: A Rational Reconstruction (cont.) 1 Goals of this Lecture Recall from last lecture Help you learn about: The decisions that were available to the designers of C The decisions that were
More informationAdvanced C Programming Topics
Introductory Medical Device Prototyping Advanced C Programming Topics, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Operations on Bits 1. Recall there are 8
More informationUnit 4. Input/Output Functions
Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen.
More informationGetting To Know Matlab
Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better
More informationIntroduction to MATLAB. Dr./ Ahmed Nagib Elmekawy Mechanical Engineering department, Alexandria university, Egypt Spring 2017.
Introduction to MATLAB Dr./ Ahmed Nagib Elmekawy Mechanical Engineering department, Alexandria university, Egypt Spring 2017 Lecture 5 Functions Writing and reading to/from command window and files Interpolation
More informationECE Lesson Plan - Class #3 Script M-files, Program Control, and Complex Numbers
ECE 201 - Lesson Plan - Class #3 Script M-files, Program Control, and Complex Numbers Script M-files : A script file is an external file that contains a sequence of MATLAB. By typing the filename, subsequent
More informationProgramming 1. Script files. help cd Example:
Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double
ME 172 Lecture 2 variables scanf() printf() 07/03/2011 ME 172 1 Data Types and Modifier Basic data types are char int float double Modifiers signed unsigned short Long 07/03/2011 ME 172 2 1 Data Types
More informationGoals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"
Goals of this Lecture The Design of C: A Rational Reconstruction Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C Why? Learning
More informationGabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming
1 Literal Constants Definition A literal or a literal constant is a value, such as a number, character or string, which may be assigned to a variable or a constant. It may also be used directly as a function
More information2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program
More informationDue date for the report is 23 May 2007
Objectives: Learn some basic Matlab commands which help you get comfortable with Matlab.. Learn to use most important command in Matlab: help, lookfor. Data entry in Microsoft excel. 3. Import data into
More informationOrdinary Differential Equation Solver Language (ODESL) Reference Manual
Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE
More informationChapter 3: Introduction to MATLAB Programming (4 th ed.)
Chapter 3: Introduction to MATLAB Programming (4 th ed.) Algorithms MATLAB scripts Input / Output o disp versus fprintf Graphs Read and write variables (.mat files) User-defined Functions o Definition
More informationNumber Systems, Scalar Types, and Input and Output
Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point
More informationStandard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)
Standard 11 Lesson 9 Introduction to C++( Up to Operators) 2MARKS 1. Why C++ is called hybrid language? C++ supports both procedural and Object Oriented Programming paradigms. Thus, C++ is called as a
More informationBasic Elements of C. Staff Incharge: S.Sasirekha
Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase
More informationC: How to Program. Week /Mar/05
1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers
More informationComputer Programming in MATLAB
Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Atatürk University Engineering Faculty Department of Mechanical Engineering User Defined Functions MATLAB has a number of built-in (compiled) functions,
More information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:
More informationMatlab I: Getting Started
August 2012 Table of Contents Section 1: Introduction...3 About this Document...3 Introduction to Matlab...4 Section 2: An Overview of Matlab...5 Access to Matlab...5 Getting Started...6 The Desktop Layout...6
More informationA Quick Tutorial on MATLAB. Zeeshan Ali
A Quick Tutorial on MATLAB Zeeshan Ali MATLAB MATLAB is a software package for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It's name
More information.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..
.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. A Simple Program. simple.c: Basics of C /* CPE 101 Fall 2008 */ /* Alex Dekhtyar */ /* A simple program */ /* This is a comment!
More informationIntroduction to MATLAB
Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming
More informationITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University
ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs
More informationTime: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:
ECE 120 Midterm 1 HKN Review Session Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location: Your Room on Compass What to bring: icard, pens/pencils, Cheat sheet (Handwritten) Overview of Review Binary IEEE
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationThe C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.
The C++ Language Input and Output Output! Output is information generated by a program.! Frequently sent the screen or a file.! An output stream is used to send information. Another type supplied by C++
More informationCSc Introduction to Computing
CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments
More informationChapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic
More information1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Review: Basic I/O in C Allowing Input from the Keyboard, Output to the Monitor
More informationFundamentals of Programming
Fundamentals of Programming Lecture 4 Input & Output Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline printf scanf putchar getchar getch getche Input and Output in
More informationStarting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA
Starting with a great calculator... Topic 5: Introduction to Programming in Matlab CSSE, UWA! MATLAB is a high level language that allows you to perform calculations on numbers, or arrays of numbers, in
More informationAnalysis Methods in Atmospheric and Oceanic Science AOSC 652. Introduction to MATLAB. Week 8, Day Oct 2014
Analysis Methods in Atmospheric and Oceanic Science 1 AOSC 652 Introduction to MATLAB Week 8, Day 1 20 Oct 2014 2 Introduction to MATLAB Matlab stands for MATrix LABoratory. Developed by http://www.mathworks.com/
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.
C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi CE 43 - Fall 97 Lecture 4 Input and Output Department of Computer Engineering Outline printf
More information17 USING THE EDITOR AND CREATING PROGRAMS AND FUNCTIONS
17 USING THE EDITOR AND CREATING PROGRAMS AND FUNCTIONS % Programs are kept in an m-file which is a series of commands kept in the file that is executed from MATLAB by typing the program (file) name from
More informationMATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).
L A B 6 M A T L A B MATLAB INTRODUCTION Matlab is a commercial product that is used widely by students and faculty and researchers at UTEP. It provides a "high-level" programming environment for computing
More informationECE Lesson Plan - Class 1 Fall, 2001
ECE 201 - Lesson Plan - Class 1 Fall, 2001 Software Development Philosophy Matrix-based numeric computation - MATrix LABoratory High-level programming language - Programming data type specification not
More informationIntroduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)
Introduction to MATLAB Programming Chapter 3 Linguaggio Programmazione Matlab-Simulink (2017/2018) Algorithms An algorithm is the sequence of steps needed to solve a problem Top-down design approach to
More informationPhysics 251 Laboratory Introduction to Spreadsheets
Physics 251 Laboratory Introduction to Spreadsheets Pre-Lab: Please do the lab-prep exercises on the web. Introduction Spreadsheets have a wide variety of uses in both the business and academic worlds.
More informationInput/Output: Advanced Concepts
Input/Output: Advanced Concepts CSE 130: Introduction to Programming in C Stony Brook University Related reading: Kelley/Pohl 1.9, 11.1 11.7 Output Formatting Review Recall that printf() employs a control
More informationC introduction: part 1
What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation
More informationFormatted Output Pearson Education, Inc. All rights reserved.
1 29 Formatted Output 2 OBJECTIVES In this chapter you will learn: To understand input and output streams. To use printf formatting. To print with field widths and precisions. To use formatting flags in
More informationSECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB
SECTION 2: PROGRAMMING WITH MATLAB MAE 4020/5020 Numerical Methods with MATLAB 2 Functions and M Files M Files 3 Script file so called due to.m filename extension Contains a series of MATLAB commands The
More informationMATLAB. Input/Output. CS101 lec
MATLAB CS101 lec24 Input/Output 2018-04-18 MATLAB Review MATLAB Review Question ( 1 2 3 4 5 6 ) How do we access 6 in this array? A A(2,1) B A(1,2) C A(3,2) D A(2,3) MATLAB Review Question ( 1 2 3 4 5
More information