필터 지우기
필터 지우기

Welcome I have a CF equation that performs a three-dimensional summation process and gives a two-dimensional result I did this process using (For Loops) in MATLAB. I want to c

조회 수: 3 (최근 30일)
clc
xm(:,:,1)= [1 2 3 4;2 3 4 5;3 4 5 6;4 5 6 7 ]
xm(:,:,2)= [2 3 4 5;3 4 5 6;4 5 6 7;5 6 7 8]
tic
[cf] =coherence_factor(xm)
toc
function [cf] = coherence_factor(xm)
for i=1:size(xm,1);
for j=1:size(xm,2);
n=size(xm,3);
cf(i,j)=(abs (sum(xm(i,j,:))).^2) / (n* sum(abs(xm(i,j,:).^2)));
end
end
end
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 3월 30일
"I want to c"
You want to what? Change the way questions on MATLAB Answers are asked?
hisham mohammed
hisham mohammed 2023년 3월 30일
I want to remove the (for loop)in this code and use matrix oprtion for this code how i can do it !

댓글을 달려면 로그인하십시오.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 3월 30일
편집: Dyuman Joshi 2023년 3월 30일
%Data
xm(:,:,1)= [1 2 3 4;2 3 4 5;3 4 5 6;4 5 6 7 ];
xm(:,:,2)= [2 3 4 5;3 4 5 6;4 5 6 7;5 6 7 8];
n=size(xm,3);
%Loop Method
for i=1:size(xm,1);
for j=1:size(xm,2);
cf1(i,j)=(abs (sum(xm(i,j,:))).^2) / (n* sum(abs(xm(i,j,:).^2)));
end
end
cf1
cf1 = 4×4
0.9000 0.9615 0.9800 0.9878 0.9615 0.9800 0.9878 0.9918 0.9800 0.9878 0.9918 0.9941 0.9878 0.9918 0.9941 0.9956
%Vectorized method
cf2 = abs(sum(xm,3).^2)./(n*sum(abs(xm.^2),3))
cf2 = 4×4
0.9000 0.9615 0.9800 0.9878 0.9615 0.9800 0.9878 0.9918 0.9800 0.9878 0.9918 0.9941 0.9878 0.9918 0.9941 0.9956

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by