Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
find location in matrix and print min and max for each column batch

Subject: find location in matrix and print min and max for each column batch

From: Michael

Date: 24 Nov, 2012 00:05:08

Message: 1 of 10

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

Subject: find location in matrix and print min and max for each column

From: dpb

Date: 24 Nov, 2012 01:06:00

Message: 2 of 10

On 11/23/2012 6:05 PM, Michael wrote:
> 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?
...
> (ii) print out the maximum value of x and its location.
> (iii) print out the minimum value of x and its location.

doc max % Read carefully all possible uses described...

...


--

Subject: find location in matrix and print min and max for each column

From: Michael

Date: 24 Nov, 2012 03:56:08

Message: 3 of 10

dpb <none@non.net> wrote in message <k8p6jg$gjh$1@speranza.aioe.org>...
> On 11/23/2012 6:05 PM, Michael wrote:
> > 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?
> ...
> > (ii) print out the maximum value of x and its location.
> > (iii) print out the minimum value of x and its location.
>
> doc max % Read carefully all possible uses described...
>
> ...

What?

Subject: find location in matrix and print min and max for each column

From: dpb

Date: 24 Nov, 2012 14:25:39

Message: 4 of 10

On 11/23/2012 9:56 PM, Michael wrote:
> dpb <none@non.net> wrote in message <k8p6jg$gjh$1@speranza.aioe.org>...
>> On 11/23/2012 6:05 PM, Michael wrote:
>> > 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?
>> ...
>> > (ii) print out the maximum value of x and its location.
>> > (iii) print out the minimum value of x and its location.
>>
>> doc max % Read carefully all possible uses described...
>>
>> ...
>
> What?

Type

doc max

at the command line and read (carefully and past the first line). Study
the various syntax forms listed...

--

Subject: find location in matrix and print min and max for each column

From: Michael

Date: 24 Nov, 2012 18:03:08

Message: 5 of 10

dpb <none@non.net> wrote in message <k8qlep$i8d$1@speranza.aioe.org>...
> On 11/23/2012 9:56 PM, Michael wrote:
> > dpb <none@non.net> wrote in message <k8p6jg$gjh$1@speranza.aioe.org>...
> >> On 11/23/2012 6:05 PM, Michael wrote:
> >> > 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?
> >> ...
> >> > (ii) print out the maximum value of x and its location.
> >> > (iii) print out the minimum value of x and its location.
> >>
> >> doc max % Read carefully all possible uses described...
> >>
> >> ...
> >
> > What?
>
> Type
>
> doc max
>
> at the command line and read (carefully and past the first line). Study
> the various syntax forms listed...
>
> --

I read the doc max info and I even have been looking in my textbook, but when I tried the different syntaxes, my program still didn't give me the batch number of the max and min temperature, pressure, and dwell time. Please Help!!!

Subject: find location in matrix and print min and max for each column

From: dpb

Date: 24 Nov, 2012 18:50:30

Message: 6 of 10

On 11/24/2012 12:03 PM, Michael wrote:
...

> I read the doc max info and I even have been looking in my textbook, but
> when I tried the different syntaxes, my program still didn't give me the
> batch number of the max and min temperature, pressure, and dwell time.
> Please Help!!!

cs-sm respondents don't actually _do_ homework problems directly as a
general rule...hints and specific questions on syntax or the like are
kosher but it would be taking from the learning process to just plop and
answer out there on a plate.

Trust me, what you need is there in the documentation...think about what
it is that you need to know to retrieve the values desired...and then
how to use what max/min can tell you to do that.

Post what you've tried...specifically for that problem, _not_ the entire
chunk of code.

--

Subject: find location in matrix and print min and max for each column

From: Michael

Date: 24 Nov, 2012 20:45:08

Message: 7 of 10

dpb <none@non.net> wrote in message <k8r4vc$psc$1@speranza.aioe.org>...
> On 11/24/2012 12:03 PM, Michael wrote:
> ...
>
> > I read the doc max info and I even have been looking in my textbook, but
> > when I tried the different syntaxes, my program still didn't give me the
> > batch number of the max and min temperature, pressure, and dwell time.
> > Please Help!!!
>
> cs-sm respondents don't actually _do_ homework problems directly as a
> general rule...hints and specific questions on syntax or the like are
> kosher but it would be taking from the learning process to just plop and
> answer out there on a plate.
>
> Trust me, what you need is there in the documentation...think about what
> it is that you need to know to retrieve the values desired...and then
> how to use what max/min can tell you to do that.
>
> Post what you've tried...specifically for that problem, _not_ the entire
> chunk of code.
>
> --

I completely understand. I don't expect you to do the problem for me, just some good advice is perfect. I think though this problem requires more than just using max and min, I believe it wants us to use max, min with the find command or something. Here is my user-defined function and what I have tried for that problem:
Also here is my suture data. The * is what I am having a problem with.

 Batch Number Temperature Pressure Dwell Time
        24551 145.5 62.3 2.23
        24582 153.7 63.2 2.52
        26553 160.3 58.9 2.51
        26623 159.5 58.9 2.01
        26642 160.3 61.2 1.98

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;

c = s(:,2);
[n,Max,Min,p] = func(150,170,c);
fprintf('The batch number with minimum temperature is: %3.0f \n', *Min*);
fprintf('The batch number with maximum temperature is: %3.0f \n \n', *Max*);

I'm am trying to print out the batch number with maximum and minimum temperature, not the max and min temperature.

Subject: find location in matrix and print min and max for each column

From: dpb

Date: 24 Nov, 2012 21:58:50

Message: 8 of 10

On 11/24/2012 2:45 PM, Michael wrote:
...

> I completely understand. I don't expect you to do the problem for me,
> just some good advice is perfect. I think though this problem requires
> more than just using max and min, I believe it wants us to use max, min
> with the find command or something....

No.

It only needs the output _available_ from the max/min functions.

Again, I can' emphasize that you need to look at all the possible ways
given for the syntax...(VBHint: return values)

--

Subject: find location in matrix and print min and max for each column

From: Michael

Date: 24 Nov, 2012 23:02:08

Message: 9 of 10

dpb <none@non.net> wrote in message <k8rg0e$mmq$1@speranza.aioe.org>...
> On 11/24/2012 2:45 PM, Michael wrote:
> ...
>
> > I completely understand. I don't expect you to do the problem for me,
> > just some good advice is perfect. I think though this problem requires
> > more than just using max and min, I believe it wants us to use max, min
> > with the find command or something....
>
> No.
>
> It only needs the output _available_ from the max/min functions.
>
> Again, I can' emphasize that you need to look at all the possible ways
> given for the syntax...(VBHint: return values)
>
> --

Ok. I will continue trying and see if I can figure it out. Thanks you for the advice. I appreciate it!

Subject: find location in matrix and print min and max for each column

From: dpb

Date: 24 Nov, 2012 23:26:13

Message: 10 of 10

On 11/24/2012 5:02 PM, Michael wrote:
> dpb <none@non.net> wrote in message <k8rg0e$mmq$1@speranza.aioe.org>...
>> On 11/24/2012 2:45 PM, Michael wrote:
>> ...
>>
>> > I completely understand. I don't expect you to do the problem for me,
>> > just some good advice is perfect. I think though this problem requires
>> > more than just using max and min, I believe it wants us to use max, min
>> > with the find command or something....
>>
>> No.
>>
>> It only needs the output _available_ from the max/min functions.
>>
>> Again, I can' emphasize that you need to look at all the possible ways
>> given for the syntax...(VBHint: return values)
>>
>> --
>
> Ok. I will continue trying and see if I can figure it out. Thanks you
> for the advice. I appreciate it!

What does the optional return value do?

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us