How do can I use every number in my loop?

조회 수: 1 (최근 30일)
Dameon Solestro
Dameon Solestro 2021년 11월 24일
답변: Walter Roberson 2021년 11월 24일
So right now I have 3 groups of 5 x values(15 x values in total. How do I perform a loop where I use the values after I get the mean?? so how would i create a matrix such that . M= [x1-Mean_allx ; x2-Mean_allx ; x3-Mean_allx ;...... ; x15-Mean_allx] ?? Could it also be possible for the value to be Matrix to be averaged?
for j=1:3
for i=1:5
x(i,j)= rand()
hold on
end
hold on
h(j)=mean(x(:,j))
Mean_allx= mean(h)
end

채택된 답변

Walter Roberson
Walter Roberson 2021년 11월 24일
for j=1:3
for i=1:5
x(i,j)= rand()
end
h(j)=mean(x(:,j))
end
Mean_allx= mean(h)

추가 답변 (1개)

the cyclist
the cyclist 2021년 11월 24일
편집: the cyclist 2021년 11월 24일
% Set the random number seed, for reproducibility
rng default
% Create the x data
x = rand(3,5);
% Mean of all the x data
Mean_allx = mean(x,'all');
% Subtract the mean from the x data
x_minus_mean = x - Mean_allx;
  댓글 수: 1
Dameon Solestro
Dameon Solestro 2021년 11월 24일
I kind of need both i and j loops.. is there a way for this to still be possible??

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by