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: West Point Bridge Design Contest
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
Graphical Interface: the function draw_truss
Saving data: – save filename – save filename array1 array2 – save filename –ascii Importing/Exporting Data 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 = >> b=[7 8 9] b = >> save arrays_a_and_b a b Loading arrays from a file: >> clear >> load arrays_a_and_b a b >> a a = >> b b = Creates file arrays_a_and_b.mat
Formatted output 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 for more details
An example: %d = put data here \n = new line The data itself Formatted output (cont.)
Escape characters: – New line ( \n ), backspace ( \b ), tab ( \t ), … Formatted output (cont.)
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.)
fprintf works element-by-element on array data: \n added for line return Formatted output (cont.)
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 w indicates “write” Formatted output to a 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