basic matrix creation question

3 次查看(过去 30 天)
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];

采纳的回答

Chris A
Chris A 2012-11-1
Try changing the last line to
r_n = [r_1' r_2' r_3' r_4' r_5' r_6'];

更多回答(1 个)

Tom
Tom 2012-11-1
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

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by