MATLAB Answers

Matrix Dimension Must Agree

30 views (last 30 days)
Dion Akmal
Dion Akmal on 17 Apr 2021 at 13:58
Commented: Walter Roberson on 18 Apr 2021 at 6:40
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

Answers (3)

David Hill
David Hill on 17 Apr 2021 at 14:25
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 on 17 Apr 2021 at 14:27
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 Comments
Matt J
Matt J on 17 Apr 2021 at 21:22
theta and l do indeed have different lengths, so it is not clear what you are trying to do in your calculation of Eteta.

Sign in to comment.


Walter Roberson
Walter Roberson on 17 Apr 2021 at 21: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 Comments
Walter Roberson
Walter Roberson on 18 Apr 2021 at 6:40
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by