Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An experiment conducted on single carbon fibers under tension at gauge length of

ID: 3854862 • Letter: A

Question

An experiment conducted on single carbon fibers under tension at gauge length of 1, 10, 20 and 50mm. Experiment
results are given in the table below and fibers.dat too. The first column in the data file represents that experiments
are conducted at the gauge length of 1, 10, 20 and 50mm respectively, the rest of 5 columns represent the strengths
at each gauge length. (HAS TO BE DONE IN MATLAB)

(a) Write a script that can read the information from data file (fibers.dat) and store them in a cell array. Do not
fill in the individual values one by one explicitly. (Hint: using loop).

(b) Re-Write a script that read the information from data file (fibers.dat) and store them in a vector of structures.
Each element of the vector is a structure with two fields: gauge length and test results, where the test results is
a vector of size 1-by-7. Do not fill in the individual values one by one explicitly. (Hint: using loop).

(c) Write a function that take a cell array(in part a)) as input argument and calculate the average, minimum
and maximum of strength at each gauge length, print column headings of ”Gauge length of”, ”Average”,
”Minimum”, ”Maximum” and corresponding results. Here is the sample output.

(d) Re-write the function of part c) that take a vector of structure(in part b)) as input argument and calculate the
average, minimum and maximum of strength at each gauge length, print column headings of ”Gauge length
of”, ”Average”, ”Minimum”, ”Maximum” and corresponding results.

fibers.dat file contains this:

1 1.116 2.0563 1.041 1.54 2.143 2.0541 2.751 10 1.215 2.6142 1.548 1.009 2.74 1.8764 1.5211 20 1.3141 2.098 2.5663 3.128 1.997 2.455 1.5444 50 1.339 2.211 2.784 3.561 2.001 1.5461 2.011

Explanation / Answer

1)Write a script that can read the information from the data file (fibers.dat) and store them in a cell array.

fileID = fopen('fibers.dat','r'); %%fopen opens the .dat file

formatSpec = '%f %f %f %f %f %f %f %f'; %%here we specify the format of the data

sizeA = [4 8]; %%size of the array

A = fscanf(fileID,formatSpec,sizeA); %%fscanf reads the data and keep in array A

fclose(fileID); %%closes the array

3)Write a function that takes a cell array(in part a)) as input argument and calculate the average, minimum

and maximum of strength at each gauge length, print column headings of ”Gauge length of”, ”Average”,

”Minimum”, ”Maximum” and corresponding results.

function fiber(A)

A=A'; %%A' specifies the transpose of the array

B=A([2:4] , : ); %deleting the first row

A=A([1] , : ); %deleting rows except the first row

A=A';

M = mean(B) %%Mean gives the average of the array

M=M';

MAX_A= Max(B); %%Max function gives the min value of array

MAX_A=MAX_A';

Min_A=Min(B) %%Min function gives the min value of array

Min_A=Min_A;

fprintf("Gauge Length of (mm) Average Length Minimum Maximum")

while (i<4)

fprintf(A(i)+" "+M(i)+ +" "+MAX_A(i)+" "+Min_A(i));

i=i+1;

end

fclose(fileID);

end

2)Re-Write a script that read the information from the data file (fibers.dat) and stores them in a vector of structures.

fileID = fopen('fibers.dat','r');

formatSpec = '%f %f %f %f %f %f %f %f';

sizeA = [4 8];

A = fscanf(fileID,formatSpec,sizeA);

i=0

j=0

field = 'f';

value = {'gauge length';

A((1:4),0);

'test results';

A((1:4,(2:end))};

s = struct(field,value)

fclose(fileID);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote