Date: Nov 23, 2012 7:05 PM Author: Michael Subject: find location in matrix and print min and max for each column batch I'm having an issue with the last part of an assignment. Part (b), ii and iii and part (e). I can't seem to be able to display the locations for part (b) or print the batch # corresponding to the min and max values for each row. Can anyone help?

"Consider the data file ?suture.txt? in Prob.5-12 (on page 150) of your textbook. The

file contains information on batches of sutures that have been rejected during a one week period. Each line contains four columns of data (the batch number,

temperature, pressure, and dwell time) . Place the content of suture.txt in a Matlab

data file with the name ?suture.mat? in your current directory. Use the Matlab

command ?load? to load the data file and place each column in an appropriate one dimensional

array.

a) First verify the data file by printing the content of suture.mat in four columns. Be

sure to label the four columns appropriately.

b) Write a user-defined function called func(a,b,x) with three input variables. Your

function func should do the following:

(i) print all the locations of the one-dimensional array x that fall outside the

interval (a,b), where b > a.

(ii) print out the maximum value of x and its location.

(iii) print out the minimum value of x and its location.

(iv) return percentage of the elements of the one-dimensional array x that are

outside the interval (a,b), where b > a.

Note: You may use the Matlab command ?find?.

c) Now using func, determine the percentages of rejected batches based on

temperature, pressure, and dwell time.

d) Using your user-defined function func, print the batch numbers corresponding to

rejected batches based on temperature, pressure, and dwell time. Also print the

percent of batches that are rejected on the basis of temperature, pressure, and

dwell time.

e) Print the batch number for the patient with the minimum and maximum

temperature, pressure, and dwell time."

----------------------------------------------------------------------------------------------------------------

Here is my main script:

% Problem 2: Data Files and User-Defined Functions

% State Problem 2

fprintf(' \n \n Problem 2 ');

% Load the suture.txt file

s = load('suture.txt');

% Format the number display

format shortg

% Display the data file in four columns

fprintf(' \n \n Batch Number Temperature Pressure Dwell Time \n');

disp(s);

% Temperature

c = s(:,2);

[n,Max,Min,p] = func(150,170,c);

fprintf('The rejected batch number(s) based on temperature is: %3.0f \n', s(n,1));

fprintf('The percent of rejected batches based on temperature is: %3.0f%% \n', p);

fprintf('The batch number with minimum temperature is: %3.1f \n', Min);

fprintf('The batch number with maximum temperature is: %3.1f \n \n', Max);

% Pressure

c = s(:,3);

[n,Max,Min,p] = func(60,70,c);

fprintf('The rejected batch number(s) based on pressure is: %3.0f \n', s(n,1));

fprintf('The percent of rejected batches based on pressure is: %3.0f%% \n', p);

fprintf('The batch number with minimum pressure is: %3.1f \n', Min);

fprintf('The batch number with maximum pressure is: %3.1f \n \n', Max);

% Dwell Time

c = s(:,4);

[n,Max,Min,p] = func(2.0,2.5,c);

fprintf('The rejected batch number(s) based on dwell time is: %3.0f \n', s(n,1));

fprintf('The percent of rejected batches based on dwell time is: %3.0f%% \n', p);

fprintf('The batch number with minimum dwell time is: %3.1f \n', Min);

fprintf('The batch number with maximum dwell time is: %3.1f \n', Max);

----------------------------------------------------------------------------------------------------------------

Here is my data file info for which I need to find the values (save as suture.text):

24551 145.5 62.3 2.13

24582 153.7 63.0 2.52

26553 160.4 58.8 2.51

26613 159.5 58.9 2.02

26624 160.5 61.5 1.98

27725 170.9 62.5 2.03

----------------------------------------------------------------------------------------------------------------

Here is my func function:

function [n,Max,Min,p] = func(a,b,x)

n = find(x<a|x>b);

Max = max(x);

Min = min(x);

p = (length(n)/length(x))*100;

end