creating a new array from a preexisting array
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rasmus Hvidberg
el 4 de Mzo. de 2019
Comentada: Rasmus Hvidberg
el 4 de Mzo. de 2019
From the following code, I want matlab to create a new array, b.
Array a should be considered as pairs of real and imaginary parts of a number like A = [R1 I1 R2 I2 R3 I3 ...] where R1 is the real part of the complex number and I1 is the complex part of the number. I want array b to contain the magnitude of the complex numbers.
a = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
b = zeros(length(a)/2)
for i = length(a)/2
b(i) = sqrt((a(i*2-1).^2) + (a(i*2).^2));
end
For some reason this creates an 8x8 array instead of a single array of 8 elements. I don't know why. Please help.
1 comentario
KSSV
el 4 de Mzo. de 2019
YOu should use:
b = zeros(1,length(a)/2)
This is wrong:
b(i) = sqrt((a(i*2-1).^2) + (a(i*2).^2));
What you are trying to do?
Respuesta aceptada
KSSV
el 4 de Mzo. de 2019
May be your are looking for this:
a = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
b = zeros(1,length(a)/2) ;
for i = 1:length(a)/2
b(i) = sqrt((2*a(i)-1).^2 + (2*a(i).^2));
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!