Matrix Dimension Must Agree
2 次查看(过去 30 天)
显示 更早的评论
can somebody help me im new at using matlab
this is my code and the error said that "Matrix Dimension Must Agree"
clc
clear
%%deklarasi variabel
n = 377;
f = 3*(10^9);
c = 3*(10^8);
lambda = c/f;
I = 1;
r = 10*lambda;
theta = [0:0.01:2*(pi)];
k = 2*(pi)/lambda;
l = [(5.1)*lambda : 0.01 : (7.1)*lambda];
%% persamaan pola radiasi
Eteta = (i.*n.*I.*exp(-i.*k.*r)/2.*(pi).*r).*((cos((k.*l/2).*cos(theta))-cos(k.*l/2))./sin(theta));
%% persamaan power pattern
rteta = abs(Eteta);
rtetadB = 10*log10(rteta);
Rteta = rtetadB;
%% Plot 2D variabel
h = figure(1);
polarplot(theta,Rteta);
%% proses normalisasi
Rthetanorm = Rteta - min(Rteta);
%% vektor sudut azimuth
Azimuth = [0:0.01:2*(pi)];
%% magnitude ternormalisasi
Rthetanorm(1,1) = 0;
%% matriks vektor baris sudut azimuth
matrix_pi = [];
%% matriks vektor baris sudut elevasi
matrix_theta = [];
%% matriks vektor baris magnitude ternormalisasi
matrix_Rthetanorm = [];
for i = 1:629
matrix_pi(i,:) = Azimuth(1,:);
matrix_theta(:,i) = theta(1,:);
matrix_Rthetanorm(:,i) = Rthetanorm(1,:);
end
%% koordinat cartesian
x = matrix_Rthetanorm.*cos(matrix_theta).*cos(matrix_pi);
y = matrix_Rthetanorm.*cos(matrix_theta).*sin(matrix_pi);
z = matrix_Rthetanorm.*sin(matrix_theta);
%% Plot 3D dari koordinat cartesian
f = figure(2);
mesh(x,y,z);
colorMap=[[0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0 0 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7]', [0 0 0 0 0.1 0.2 0.3 0.9 0.9 0.9 0.9 0.3 0.2 0.1 0 0 0 0]', [0 0 0 0 0.1 0.2 0.3 0.4 0 0 0.4 0.3 0.2 0.1 0 0 0 0]'];
colormap(colorMap);
colorbar
0 个评论
回答(3 个)
David Hill
2021-4-17
theta = linspace(0,2*(pi),629);
l = linspace((5.1)*lambda,(7.1)*lambda,629);
Azimuth = linspace(0,2*(pi),629);%these all need to be the same size, use linspace
0 个评论
Matt J
2021-4-17
theta and l do indeed have different lengths, so it is not clear what you are trying to do in your calculation of Eteta.
n = 377;
f = 3*(10^9);
c = 3*(10^8);
lambda = c/f;
I = 1;
r = 10*lambda;
theta = [0:0.01:2*(pi)];
k = 2*(pi)/lambda;
l = [(5.1)*lambda : 0.01 : (7.1)*lambda];
whos theta l
2 个评论
Matt J
2021-4-17
theta and l do indeed have different lengths, so it is not clear what you are trying to do in your calculation of Eteta.
Walter Roberson
2021-4-17
clc
clear
%%deklarasi variabel
n = 377;
f = 3*(10^9);
c = 3*(10^8);
lambda = c/f;
I = 1;
r = 10*lambda;
theta = [0:0.01:2*(pi)];
k = 2*(pi)/lambda;
l = [(5.1)*lambda : 0.01 : (7.1)*lambda].'; %only change
%% persamaan pola radiasi
Eteta = (i.*n.*I.*exp(-i.*k.*r)/2.*(pi).*r).*((cos((k.*l/2).*cos(theta))-cos(k.*l/2))./sin(theta));
%% persamaan power pattern
rteta = abs(Eteta);
rtetadB = 10*log10(rteta);
Rteta = rtetadB;
%% Plot 2D variabel
h = figure(1);
polarplot(theta,Rteta);
%% proses normalisasi
Rthetanorm = Rteta - min(Rteta);
%% vektor sudut azimuth
Azimuth = [0:0.01:2*(pi)];
%% magnitude ternormalisasi
Rthetanorm(1,1) = 0;
%% matriks vektor baris sudut azimuth
matrix_pi = [];
%% matriks vektor baris sudut elevasi
matrix_theta = [];
%% matriks vektor baris magnitude ternormalisasi
matrix_Rthetanorm = [];
for i = 1:629
matrix_pi(i,:) = Azimuth(1,:);
matrix_theta(:,i) = theta(1,:);
matrix_Rthetanorm(:,i) = Rthetanorm(1,:);
end
%% koordinat cartesian
x = matrix_Rthetanorm.*cos(matrix_theta).*cos(matrix_pi);
y = matrix_Rthetanorm.*cos(matrix_theta).*sin(matrix_pi);
z = matrix_Rthetanorm.*sin(matrix_theta);
%% Plot 3D dari koordinat cartesian
f = figure(2);
mesh(x,y,z);
colorMap=[[0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0 0 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7]', [0 0 0 0 0.1 0.2 0.3 0.9 0.9 0.9 0.9 0.3 0.2 0.1 0 0 0 0]', [0 0 0 0 0.1 0.2 0.3 0.4 0 0 0.4 0.3 0.2 0.1 0 0 0 0]'];
colormap(colorMap);
colorbar
2 个评论
Walter Roberson
2021-4-18
It is already beening made in different figures ? The 2D plot is going into figure 1, and the 3d plot is going into figure 2.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!