MATLAB Answers

Matrix Dimension Must Agree

조회 수: 30(최근 30일)
Dion Akmal
Dion Akmal 17 Apr 2021 13:58
댓글: Walter Roberson 18 Apr 2021 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

답변(3개)

David Hill
David Hill 17 Apr 2021 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 17 Apr 2021 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
Matt J
Matt J 17 Apr 2021 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.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 17 Apr 2021 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
Walter Roberson
Walter Roberson 18 Apr 2021 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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by