Looping for calculate parameter

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by