how to write a code for cosine similarity mentioned in images?

5 vues (au cours des 30 derniers jours)
Fariba Dehghan
Fariba Dehghan le 7 Jan 2022
I want to write the code for function that I mentioned in the images, where M = 96. The output power for the ith day is pi =[p , . . . , piM ]T , ∀i ∈ [1, . . . , 366]. j ∈ [1, . . .,366] and pjm is the mth output power point in the jth day, pj = [p , . . . , pjM ]T. k is an interval value between the ith day and the jth day, i + k = j. I wrote following code but it does not work correctly.
can anyone help me on this?
thanks for your consideration.
CS=zeros(96,96); % Initialise output
syms k
h=1/(366-k);
for m=1:96
for i=1:366
j=i+k;
if j<=366
Pi(:,i)=mat_solar_(:,i);
Pj(:,i)=mat_solar_(:,i:j);
end
end
end

Réponses (1)

yanqi liu
yanqi liu le 8 Jan 2022
clc; clear all; close all;
x = 1:9;
y = magic(3);
x = x(:)';
y = y(:)';
r = 1-pdist2(x, y, 'cosine')
r = 0.7895
% self define
a = sum(x.*y);
b = norm(x)*norm(y);
c = a/b
c = 0.7895

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by