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 月 2 日
many thanks

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeLanguage Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by