Hello, how can I calculate the row and column by inserting a 3D matrix using this equation

1 Ansicht (letzte 30 Tage)
clc
clear all
close all
xm= [5 5 5 5;5 -4 -3 -2;5 -1 0 1;5 2 3 4]
xm = 4×4
5 5 5 5 5 -4 -3 -2 5 -1 0 1 5 2 3 4
n=length(xm);
[cf] =coherence_factor(xm,n)
cf = 1×4
1.0000 0.0741 0.2315 0.9074
function [cf] = coherence_factor(xm,n)
for i=1:4;
n=length(xm(i,:));
%%%%%%%%%%%%%%%%%%%% equation %%%%%%%%%%%%%%%%%%%
cf(i)=(abs (sum(xm(i,:))).^2) / (n* sum(abs(xm(i,:).^2)));
end
CF=cf(i);
end
  3 Kommentare
Jan
Jan am 1 Mär. 2023
@hisham mohammed: You define n as input argument, but overwrite it by the same value in each iteration. Of course all xm(i,:) have the same length. So use this before the loop:
m = size(xm, 2);
The line CF=cf(i); is useless, because CF is not replied. Currently the output is a vector. It is not clear how you want to expand ot to 3D.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by