Hello, how can I calculate the row and column by inserting a 3D matrix using this equation,, so that the input 3D matrix and output 2D matrix

1 view (last 30 days)
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

Answers (1)

DUY Nguyen
DUY Nguyen on 2 Mar 2023
Hi, you mean that with your given function, we need to calculate the factor for 3D matrix right?
% Define the input 3D matrix
xm = cat(3, [5 5 5 5;5 -4 -3 -2;5 -1 0 1;5 2 3 4], [4 4 4 4;4 -3 -2 -1;4 0 1 2;4 3 4 5]);
% Get the number of rows and columns in the input matrix
[~,n,~] = size(xm);
% Initialize the output coherence factor matrix
cf = zeros(n, size(xm,3));
% Calculate coherence factor for each slice of the 3D matrix
for i = 1:size(xm, 3)
cf(:,i) = (abs(sum(xm(:,:,i), 2)).^2) ./ (n * sum(abs(xm(:,:,i)).^2, 2));
end
% Display the input and output matrices
disp('Input 3D matrix:')
Input 3D matrix:
disp(xm)
(:,:,1) = 5 5 5 5 5 -4 -3 -2 5 -1 0 1 5 2 3 4 (:,:,2) = 4 4 4 4 4 -3 -2 -1 4 0 1 2 4 3 4 5
disp('Output coherence factor matrix:')
Output coherence factor matrix:
disp(cf)
1.0000 1.0000 0.0741 0.0333 0.2315 0.5833 0.9074 0.9697

Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!