Looping for calculate parameter

1 Ansicht (letzte 30 Tage)
Guilherme Lopes de Campos
Guilherme Lopes de Campos am 18 Feb. 2019
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

Akzeptierte Antwort

Jan
Jan am 18 Feb. 2019
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 Kommentar
Guilherme Lopes de Campos
Guilherme Lopes de Campos am 18 Feb. 2019
Hi Jan,
The code works, thank you very much for help!!
I am grateful for help,
Guilherme

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by