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 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    hisham mohammed
 el 30 de Mzo. de 2023
  
    
    
    
    
    Editada: Dyuman Joshi
      
      
 el 30 de Mzo. de 2023
            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 comentarios
  Dyuman Joshi
      
      
 el 30 de Mzo. de 2023
				"I want to c"
You want to what? Change the way questions on MATLAB Answers are asked?
Respuesta aceptada
  Dyuman Joshi
      
      
 el 30 de Mzo. de 2023
        
      Editada: Dyuman Joshi
      
      
 el 30 de Mzo. de 2023
  
      %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
%Vectorized method
cf2 = abs(sum(xm,3).^2)./(n*sum(abs(xm.^2),3))
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!