Inputting a vector of data for statical analysis

1 visualizzazione (ultimi 30 giorni)
Tom Nunns
Tom Nunns il 4 Apr 2015
Risposto: Philip Caplan il 13 Apr 2015
Hi,
Im trying to write a function to accept the vector of fuel efficiency values in mpg and return (a) the mean value, (b) the standard deviation of values, and (c) the percentage of cars with a fuel efficiency value below 65.7 mpg E is the vector containing measured efficiency values in mpg, xMean and xStDv are the mean and standard deviation of fuel efficiencies respectively and accept is the percentage of cars with efficiency below 65.7 mpg.
How can i turn E into a vector of values? Below is how far i have got.
function [xMean,xStDv,accept] = Q2_616685 (E)
xMean = mean(E);
xMean(length(E)<5)=NaN;
maxvalue = max(E);
minvalue = min(E);
xStDv = maxvalue-minvalue;
xStDv(length(E)<5)=NaN;
lowvalue = find(E<67.5);
lengthvectororig = length(E);
lengthvectornew = length(lowvalue);
accept = (100/lengthvectororig)*lengthvectornew;
accept(length(E)<5)=NaN;
%MATLAB function to accept the vector of fuel efficiency values in mpg and
%return (a) the mean value, (b) the standard deviation of values, and (c) the
%percentage of cars with a fuel efficiency value below 65.7 mpg (the efficiency of a
%Peugeot 108).
%Where E is the vector containing measured efficiency values in mpg, xMean and
%xStDv are the mean and standard deviation of fuel efficiencies respectively and
%accept is the percentage of cars with efficiency below 65.7 mpg.
end
  2 Commenti
Geoff Hayes
Geoff Hayes il 4 Apr 2015
Tom - please clarify what you mean by how you can turn E into a vector of values? If you want E to be a vector (or array) then define it as
E = [1 2 3 4 4.5 78.44];
and pass it into the function as
[xMean,xStDv,accept] = Q2_616685(E);
Tom Nunns
Tom Nunns il 4 Apr 2015
Hi Geoff,
E needs to equal a range of fuel efficiency figures, its been worded as that E needs to equal a vector of elements where the elements are the fuel efficiency figures.
How can I input a range of values as a syntax that will equate to E? Ive been told that the syntax should take the form.
>> [xMean,xStDv,accept] = Q2_616685(E);
Although E would be a single element, how can i transpose this into a array or vector?
Thanks,
Tom

Accedi per commentare.

Risposte (1)

Philip Caplan
Philip Caplan il 13 Apr 2015
Based on your application, I assume you mean that you have multiple efficiency values for each car. That is, by "vector of values", you have a vector of cars with multiple values, say highway, city and combined mpg. If this is the case, then E will be a two dimensional array and you can use the 'dim' option to "mean" and "std" to extract the appropriate mean and standard deviation, respectively, from E.
For example, if we examine the efficiency values of a Volkswagen GTI and a Toyota Prius:
>> E = [ 25,28,34 ; % GTI
51,50,49]; % Prius
>> xMean = mean(E,2); % average efficiency of each car
>> xStDv = std(E,1,2); % standard deviation of each car
>> ncars = size(E,1);
>> accept = length(find(xMean<65.7))/ncars;
For more information on the 'dim' option to "mean" and "std", please see:
and

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by