CEE 15 Introduction to Computing for Civil Engineers 5 - Plotting Capabilities

CEE 15 Introduction to Computing for Civil Engineers 5 - Plotting Capabilities

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CEE 15 Introduction to Computing for Civil Engineers 38 Chapter 5 Plotting Capabilities 5.1. X – Y Plot Our objective is to generate x-y plot from data stored in 2 vectors. x = time, s y = temp, ° F 0 54.2 1 58.5 2 63.8 3 64.2 There are 3 ways to read this data. The data can be read explicitly. For example, x=[0 1 2 3]; y=[54.2 58.5 63.8 64.2]; disp(x); disp(y); plot(x,y),. .. title('Temperature Measurement'),. .. xlabel('time, s'),. .. ylabel('temp, °F'),. .. grid will give the following output in the command window: 0 1 2 3 54.2000 58.5000 63.8000 64.2000 and the following figure in the graphic window: The data can be read using the user input. For example consider the following program: x=input('give the values of time'); y=input('give the values of temperature'); disp(x); disp(y); plot(x,y),. .. title('Temperature Measurement'),. .. xlabel('time, s'),. .. ylabel('temp, °F'),. ..
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CEE 15 Introduction to Computing for Civil Engineers 39 grid The above program will give us the following output in the command window: give the values of time [0 1 2 3] give the values of temperature [54.2 58.5 63.8 64.2] 0 1 2 3 54.2000 58.5000 63.8000 64.2000 It will also give us the same plot in the graphic window. The data can be read from an ASCII file into a matrix and stored in the vectors using colon operator . For example, let us consider the following file ( data.dat ): 0 1 2 3 54.2 58.5 63.8 64.2 and the following program: load data.dat; disp(data); x=data(1,:); y=data(2,:); plot(x,y),. .. title('Temperature Measurement'),. .. xlabel('time, s'),. .. ylabel('temp, °F'),. .. grid The output in the command window will be : 0 1.0000 2.0000 3.0000 54.2000 58.5000 63.8000 64.2000 and the plot remains the same. We could have also stored the data in a mat file and read the values of time and temperature from there. We can also have two graphic windows at the same time. For example, load data.dat; disp(data); x=data(1,:); y=data(2,:); plot(x,y),. .. title('Temperature Measurement'),. .. xlabel('time, s'),. .. ylabel('temp, °F'),. .. grid plot(y,x),. .. title('Temperature Measurement'),. .. ylabel('time, s'),. .. xlabel('temp, °F'),. ..
Background image of page 2
CEE 15 Introduction to Computing for Civil Engineers 40 grid will give us only second plot but load data.dat; disp(data); x=data(1,:); y=data(2,:); figure(1) plot(x,y),. .. title('Temperature Measurement'),. .. xlabel('time, s'),. .. ylabel('temp, °F'),. .. grid figure(2) plot(y,x),. .. title('Temperature Measurement'),. .. ylabel('time, s'),. .. xlabel('temp, °F'),. .. grid will give us both the plots. 5.2. 2-D Plot Labels title( ‘ text ’) This command writes the text as a title at the top of the current plot. xlabel( ‘ text’ ) This command writes the text beneath the x-axis on the current plot. ylabel( ‘ This command writes the text beside the y-axis on the current plot. text(x,y, ’ This command writes the text on the graphics screen at the points specified by the coordinates (x,y) using the axes from the current plot. If x and y are vectors then the text is written in each point. gtext( ‘ This command writes the text at the position on the graphics screen indicated by the mouse or arrow keys.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/28/2011 for the course CE 13972 taught by Professor Chow during the Spring '09 term at University of California, Berkeley.

Page1 / 26

CEE 15 Introduction to Computing for Civil Engineers 5 - Plotting Capabilities

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online