creating a new array from a preexisting array
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rasmus Hvidberg
am 4 Mär. 2019
Kommentiert: Rasmus Hvidberg
am 4 Mär. 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 Kommentar
KSSV
am 4 Mär. 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?
Akzeptierte Antwort
KSSV
am 4 Mär. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!