changeset 3:7f4c22114134

Implement polyFeatures
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Mon, 21 Nov 2011 00:38:41 -0500
parents 882ffde0ce47
children 4b6c21158ba6
files polyFeatures.m
diffstat 1 files changed, 7 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/polyFeatures.m
+++ b/polyFeatures.m
@@ -1,25 +1,10 @@
 function [X_poly] = polyFeatures(X, p)
-%POLYFEATURES Maps X (1D vector) into the p-th power
-%   [X_poly] = POLYFEATURES(X, p) takes a data matrix X (size m x 1) and
-%   maps each example into its polynomial features where
-%   X_poly(i, :) = [X(i) X(i).^2 X(i).^3 ...  X(i).^p];
-%
-
-
-% You need to return the following variables correctly.
-X_poly = zeros(numel(X), p);
+##POLYFEATURES Maps X (1D vector) into the p-th power
+##   [X_poly] = POLYFEATURES(X, p) takes a data matrix X (size m x 1) and
+##   maps each example into its polynomial features where
+##   X_poly(i, :) = [X(i) X(i).^2 X(i).^3 ...  X(i).^p];
+##
 
-% ====================== YOUR CODE HERE ======================
-% Instructions: Given a vector X, return a matrix X_poly where the p-th 
-%               column of X contains the values of X to the p-th power.
-%
-% 
-
+  X_poly = bsxfun (@power, X, 1:p);
 
-
-
-
-
-% =========================================================================
-
-end
+endfunction