basic matrix creation question

5 visualizaciones (últimos 30 días)
Tom
Tom el 1 de Nov. de 2012
Can anyone help me change this code so that I get r_n in one line rather than 7? Many thanks
clear all; close all;
inc = 180;
N = 6;
thetaDeg(1:90) = linspace(270,359,90); %allocate values into thetaDeg...
thetaDeg(91:180) = linspace(0,89,90); %covering from 270-360 & 0-90
thetaRad= (pi/180).*thetaDeg; %convert degrees axis to Rad axis
r = 100;
d = 0.2;
n = linspace(1,N,N)';
x_n = n.*0;
y_n = ((N - (2*n - 1))./2).*d;
x_R = r.*cos(thetaRad);
y_R = r.*sin(thetaRad);
r_1 = sqrt((x_R - x_n(1)).^2 + (y_R - y_n(1)).^2);
r_2 = sqrt((x_R - x_n(2)).^2 + (y_R - y_n(2)).^2);
r_3 = sqrt((x_R - x_n(3)).^2 + (y_R - y_n(3)).^2);
r_4 = sqrt((x_R - x_n(4)).^2 + (y_R - y_n(4)).^2);
r_5 = sqrt((x_R - x_n(5)).^2 + (y_R - y_n(5)).^2);
r_6 = sqrt((x_R - x_n(6)).^2 + (y_R - y_n(6)).^2);
r_n = [r_1 r_2 r_3 r_4 r_5 r_6];

Respuesta aceptada

Chris A
Chris A el 1 de Nov. de 2012
Try changing the last line to
r_n = [r_1' r_2' r_3' r_4' r_5' r_6'];

Más respuestas (1)

Tom
Tom el 1 de Nov. de 2012
Think I did it: -
clear all; close all;
inc = 180;
N = 6;
thetaDeg(1:90) = linspace(270,359,90); %allocate values into thetaDeg...
thetaDeg(91:180) = linspace(0,89,90); %covering from 270-360 & 0-90
thetaRad= (pi/180).*thetaDeg; %convert degrees axis to Rad axis
r = 0.5; %distance of receiver from source in m
d = 0.2;
n = linspace(1,N,N)';
x_n = n.*0;
y_n = ((N - (2*n - 1))./2).*d;
x_R = r.*cos(thetaRad);
y_R = r.*sin(thetaRad);
r_n = zeros(N,inc);
for j = 1:N;
r_n(j,:)= sqrt((x_R - x_n(j)).^2 + (y_R - y_n(j)).^2);
end
Not sure though

Categorías

Más información sobre Language Fundamentals 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!

Translated by