how to write a code for cosine similarity mentioned in images?
Show older comments
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
Answers (1)
clc; clear all; close all;
x = 1:9;
y = magic(3);
x = x(:)';
y = y(:)';
r = 1-pdist2(x, y, 'cosine')
% self define
a = sum(x.*y);
b = norm(x)*norm(y);
c = a/b
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!