Matrix Dimension Must Agree

2 次查看(过去 30 天)
Dion Akmal
Dion Akmal 2021-4-17
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));
Arrays have incompatible sizes for this operation.
%% 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

回答(3 个)

David Hill
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

Matt J
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
Name Size Bytes Class Attributes l 1x21 168 double theta 1x629 5032 double
  2 个评论
Dion Akmal
Dion Akmal 2021-4-17
so what can i do to make my code works and show all Etheta at the figure, can you help me ?
Matt J
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
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 个评论
Dion Akmal
Dion Akmal 2021-4-17
did you know how to make it in diferent figure ?
Walter Roberson
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by