Matrix Dimension Must Agree

2 views (last 30 days)
Dion Akmal
Dion Akmal on 17 Apr 2021
Commented: Walter Roberson on 18 Apr 2021
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
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
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
Dion Akmal
Dion Akmal on 17 Apr 2021
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 on 17 Apr 2021
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
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
Dion Akmal
Dion Akmal on 17 Apr 2021
did you know how to make it in diferent figure ?
Walter Roberson
Walter Roberson on 18 Apr 2021
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.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!