MATLAB Answers

How can I represent the mean in figure

1 view (last 30 days)
will99 on 11 Apr 2019
Commented: Star Strider on 11 Apr 2019
basically I have this code to de center the data by shifting it which do the following
find the mean of each vector and substract the mean from the corrsponding data
I want to represent the data in figure how can I do that ?
f = xlsread('data.xlsx');
s= size(f,2);
m = zeros(size(f));
for i = 1:s
m(:,i) = f(:,i)-mean(f(:,i));


Sign in to comment.

Answers (2)

Star Strider
Star Strider on 11 Apr 2019
You are taking the mean of each column of ‘f’, which is what the mean function does by default.
Try this:
m = f - mean(f)
Experiment to get the resullt you want.


Show 1 older comment
Star Strider
Star Strider on 11 Apr 2019
I am not certain what you intend by ‘decentered’.
If you want to subtract the value that is mid-way in the values of the column vectors in your matrix, use the median function instead of mean. The code is otherwise the same. (The mean and median may be close to being the same values in some situations, however in others they can be quite different. What you do depends on the result you want.)
will99 on 11 Apr 2019
I'm trying to perform PCA without PCA matlab function and the first step was to get the mean of the vector nad substract it from the corrsponding data so it can have mean of zero I want to check if the new data have mean of zero so I want to know how can I plot it like the one in the example
Star Strider
Star Strider on 11 Apr 2019
Assuming ‘f’ is an (Nx2) matrix, I would do this:
m = f - mean(f);
plot(m(:,1), m(:,2), '+')
You can then use the MATLAB cov and eig functions to get the covariance matrix and its eigenvalues.

Sign in to comment.

Steven Lord
Steven Lord on 11 Apr 2019
You can 'center' your data using the normalize function.
As for "represent the data in figure" do you mean you want to plot the centered data? If not can you say more about what type of visualization you want to create?
dicerolls = randi(6, 1, 100);
centeredDicerolls = normalize(dicerolls, 'center');
Although for rolling six-sided dice, you may want to subtract off the theoretical mean of 3.5 instead of the mean of your set of rolls.
dicerollsMinus3p5 = normalize(dicerolls, 'center', 3.5);

  1 Comment

will99 on 11 Apr 2019
yeah I want to plot the data before and after it got centered and shifted

Sign in to comment.

Sign in to answer this question.