basic matrix creation question

조회 수: 1 (최근 30일)
Tom
Tom 2012년 11월 1일
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