How to iterate across a specific diagonal?
    6 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Karen Smith
 el 28 de Dic. de 2021
  
    
    
    
    
    Comentada: Karen Smith
 el 28 de Dic. de 2021
            Hello, I am a beginner to matlab and wondering if anyone can help me with this specific problem. Here is my code 
N1=2;
N2=2;
nband=1;
n=(N1*N2)*2*nband;
t=4;
HM = zeros(n);
% upper t diagonal
for ii = (N1*N2*nband):n
    HM(ii,n+1-ii) = t
end
HM
% end
What I am trying to do is get a diagonal of 4's or the t variable across the the half diagonal of the matrix. Here is an image for reference. It must work for all values of N1 and N2. For example, if N1 =3, N2=2, then I would like the 8th diagonal to be iterated through the t variable. It is basically half of the n dimension. I am stuck. Any help is appreciated if possible! Thank you so much

1 comentario
Respuesta aceptada
  Voss
      
      
 el 28 de Dic. de 2021
        N1=2;
N2=2;
nband=1;
n=(N1*N2)*2*nband;
t=4;
HM = zeros(n);
% upper t diagonal
for ii = 1:(N1*N2*nband)
    HM(ii,(N1*N2*nband)+1-ii) = t;
end
HM
Más respuestas (0)
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices 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!


