Looping for calculate parameter

1 vue (au cours des 30 derniers jours)
Guilherme Lopes de Campos
Guilherme Lopes de Campos le 18 Fév 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

Réponse acceptée

Jan
Jan le 18 Fév 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 commentaire
Guilherme Lopes de Campos
Guilherme Lopes de Campos le 18 Fév 2019
Hi Jan,
The code works, thank you very much for help!!
I am grateful for help,
Guilherme

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by