140 likes | 389 Views
EGR 106 – Truss Design Project (cont.). Truss design programs Graphical interface tools in Matlab Saving and loading data Formatted output Project Assignment – part #2. Examples of truss design programs. Johns Hopkins University: http://www.jhu.edu/~virtlab/bridge/truss.htm
E N D
EGR 106 – Truss Design Project (cont.) • Truss design programs • Graphical interface tools in Matlab • Saving and loading data • Formatted output • Project Assignment – part #2
Examples of truss design programs Johns Hopkins University: http://www.jhu.edu/~virtlab/bridge/truss.htm West Point Bridge Design Contest http://bridgecontest.usma.edu/
Graphical Interface Tools • The function draw_truss will be provided to allow for graphical input of joint coordinates and member definitions • To use this function: • Download the file draw_truss.m from the course web page and save it in your current directory • Include the following command in your code: [joint_def,member_def]=draw_truss
Importing/Exporting Data • Saving data: • save filename • save filename array1 array2 • save filename –ascii • Reading in (loading) data: • load filename • load filename array1 array2 • load filename –ascii
Importing/Exporting Data - example Saving arrays to file: >> clear >> a=[1 2 3; 4 5 6] a = 1 2 3 4 5 6 >> b=[7 8 9] b = 7 8 9 >> save arrays_a_and_b a b Loading arrays from a file: >> clear >> load arrays_a_and_b a b >> a a = 1 2 3 4 5 6 >> b b = 7 8 9 Creates file arrays_a_and_b.mat
Formatted print command: fprintf(format,data) Combines text and data Allows complete control of the output format is a string (in quotes) containing text and control commands (using \ or %) See text pages 87-94 for more details Formatted output
The data itself \n = new line Formatted output (cont.) An example: %d = put data here
Formatted output (cont.) Escape characters: • New line ( \n ), backspace ( \b ), tab ( \t ), …
Conversion codes for data: Decimal ( %d ), character ( %c ), exponential notation ( %e ), fixed precision ( %f ), … Can add field width and precision information: 5 characters wide, 2 after the decimal point Formatted output (cont.)
Formatted output (cont.) fprintf works element-by-element on array data: \n added for line return
w indicates “write” Formatted output to a file To write to a file: fid = fopen( 'name', 'w' ) fprintf(fid,format,data) … fclose(fid) • fid is a variable name to specify which file • name is the name of the file
Truss Project – Assignment #2* Starting with your code from assignment #1: • Allow user to load results from previous design • Use function draw_truss to create new design • Develop code to allow user to define boundary conditions, forces and member width and thickness • Compute total length of members, mass of each member and total mass of truss • Allow user to save truss design • Have code create output file summarizing design parameters • Look for additional features to make your code more user friendly * See handout for details