problem using polyfitn with for loop and nchoosek

1 visualizzazione (ultimi 30 giorni)
hi, i have this problem, i need to create with my matrix a for loop with polyfitn using nchoosek with every 2 single combination of column vectors.
my matrix is ( every column[loudness,flustr.....] is the variable x of polyfitn):
Loudness=[2.79;3.16;3.71;2.29;2.49;2.64;2.9;2.79;2.91;3.35];
FlucStr=[0.0256;0.0277;0.0311;0.0246;0.021;0.0199;0.0194;0.0256;0.0213;0.0208];
Roughness=[0.491;0.6;0.728;0.34;0.425;0.515;0.617;0.491;0.389;0.438];
Sharpness=[1.03;1.11;1.21;0.887;0.934;0.954;0.985;1.03;1.04;1.12];
Leq=[39.7;40.9;42.6;38.1;38.9;39.5;40.6;39.7;40.3;41.7];
SIL=[29.4;30.9;32.9;26.9;28;28.8;30.1;29.4;28.8;30];
Tonality=[0.133;0.128;0.113;0.153;0.14;0.131;0.118;0.133;0.203;0.18];
Kurtosis=[2.2;2.2;2.2;2.44;2.49;2.48;2.45;2.2;2.39;2.38];
metriche=[Loudness FlucStr Roughness Sharpness Leq SIL Tonality Kurtosis];
and subjective is(is the variable y of polyfitn):
subjective=[7.5;7.02;6.94;7.91;7.96;7.91;7.78;7.42;7.86;7.47];
how can i calculate polyfitn using a for loop and nchoosek???

Risposte (1)

Rishabh Mishra
Rishabh Mishra il 31 Ago 2020
Hi mohamed,
I assume that
  • You are using the matrix ‘metriche’ as input data for the ‘polyfitn’ function.
  • The vector ‘subjective’ is used as output data for ‘polyfitn’ function.
  • You want to apply ‘polyfitn’ function on each combination of 2 columns out of the 8 columns of ‘metriche’ using for loop, ‘nchoosek’ & ‘polyfitn’ functions.
Refer to the code below:
% create the required matrix from given columns
metriche = [Loudness FlucStr Roughness Sharpness Leq SIL Tonality Kurtosis]
% 'sz' stores number of columns in 'metriche'
number_of_columns = size(metriche,2)
% 'indices' stores an array of column numbers
indices = 1:number_of_columns
% 'idx' is a vector
% 'idx' stores all the column combinations when 2 columns are chosen at a
% time out of given 8 columns
idx = nchoosek(indices,2)
% use for loop to evaluate polyfit for each of the column combinations
for k = 1:size(idx,1)
% the polyfit is linear in nature (1-degree)
degree = 1
% apply polyfitn on combinations of 2 columns from 'metriche' as inputs
% 'subjective' is the output vector
% the polynomial fir is a 1-Degree fit
evaluated_polyfit = polyfitn(metriche(:,[idx(k,1) idx(k,2)]), subjective, degree)
end
For better understanding, refer to documentation of ‘nchoosek’ function in this link, and refer to the section on how combinations of elements are generated from vectors.
Hope this helps.

Community Treasure Hunt

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

Start Hunting!

Translated by