필터 지우기
필터 지우기

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 (최근 30일)
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

답변 (1개)

DUY Nguyen
DUY Nguyen 2023년 3월 2일
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

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by