Looping for calculate parameter

조회 수: 1 (최근 30일)
Guilherme Lopes de Campos
Guilherme Lopes de Campos 2019년 2월 18일
댓글: Guilherme Lopes de Campos 2019년 2월 18일
Hi MATLAB community,
I am trying create a structure to calculate a parameter,
For made this, I would to calculate de a(1)*F(:,1)+a(2)*F(:,2)+a3*F(:,3)......until a(i)*F(i), respectily until that total number of parameters ((i=number of factors), 4 in the case). I have a doubt if I use for or while for this structure.
Could you help me?
Thank you very much
Guilherme Lopes de Campos
correlation=corrcoef(X); % size X(324,19)
eigvalue = eig(correlation);
factor = nnz(eigvalue>=1);% number of factor ( 4 in the case)
nonfactor = nnz(eigvalue<1);
sumeigvalue = sum(eigvalue);
eigvalue = eig(correlation);
[n,j] = size(eigvalue)
for i = 1:n
if eigvalue(i)>=1;
a(i)= eigvalue(i); %obtained the vector of a(i)
end
end
a = sort(a,'descend')
for i=1:factor
parameter = a(i)*F(:,i); % F is a matrix (324,4)
end
Guilherme

채택된 답변

Jan
Jan 2019년 2월 18일
With a FOR loop:
S = 0;
for k = 1:numel(a)
S = S + a(k) * F(:, k);
end
Or without a loop:
S = F(:, 1:numel(a)) * a(:);
  댓글 수: 1
Guilherme Lopes de Campos
Guilherme Lopes de Campos 2019년 2월 18일
Hi Jan,
The code works, thank you very much for help!!
I am grateful for help,
Guilherme

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by