how to fix the error

5 ビュー (過去 30 日間)
Zoha Yaghmayi Benis
Zoha Yaghmayi Benis 2022 年 2 月 28 日
回答済み: David Hill 2022 年 2 月 28 日
function [X_norm, mu, sigma] = featureNormalize(x)
%FEATURENORMALIZE Normalizes the features in X
% FEATURENORMALIZE(X) returns a normalized version of X where
% the mean value of each feature is 0 and the standard deviation
% is 1. This is often a good preprocessing step to do when
% working with learning algorithms.
% You need to set these values correctly
X_norm= x;
mu = zeros(1, size(x, 2));
sigma = zeros(1, size(x, 2));
% ====================== YOUR CODE HERE ======================
% Instructions: First, for each feature dimension, compute the mean
% of the feature and subtract it from the dataset,
% storing the mean value in mu. Next, compute the
% standard deviation of each feature and divide
% each feature by it's standard deviation, storing
% the standard deviation in sigma.
%
% Note that X is a matrix where each column is a
% feature and each row is an example. You need
% to perform the normalization separately for
% each feature.
%
% Hint: You might find the 'mean' and 'std' functions useful.
%
for l=1:size(x,2)
mu=mean(x(:,l));
sigma=std(x(:,l));
X_norm=(x(:, l) - mu)./sigma;
end
  3 件のコメント
Zoha Yaghmayi Benis
Zoha Yaghmayi Benis 2022 年 2 月 28 日
Not enough input arguments.
Error in featureNormalize (line 9)
X_norm= x;
Stephen23
Stephen23 2022 年 2 月 28 日
@Zoha Yaghmayi Benis: did you define the input x when you called the function?

サインインしてコメントする。

回答 (1 件)

David Hill
David Hill 2022 年 2 月 28 日
for l=1:size(x,2)
mu(l)=mean(x(:,l));
sigma(l)=std(x(:,l));
end
X_norm=(x-mu)./sigma;
Alternatively, no for-loop is needed.
mu=mean(x);
sigma=std(x);
X_norm=(x-mu)./sigma;

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by