Asked by Stan
on 6 Apr 2013

Hi, im new to matlab. Im having trouble with the following code. I have to do a plot of "gamma" in the end, but I get an error message saying that the matrix dimension must agree.

%% %universal constants c = 345; rho = 407 / c; L = 1; %frequency here N = 5; % number of sections dx = L / N; T = (L / c) / N; Fs = 1 / T; % sample rate required npoints = 2^12; f = linspace(0, Fs, npoints); % frequency vector %equations here w = 2*pi*f; s = i*w; rc = 0.00375; rrad = c / w; Ac = pi*(rc^2); Arad = 2*pi*(rrad^2); z0 = rho*c/Ac; Yrad = (Arad/(s*rc*rho))+(Arad/(rho*c)); Zrad = 1 / Yrad; gamma = (Zrad-z0)/(Zrad+z0) plot(abs(gamma)) end

Have a great day!

*No products are associated with this question.*

Answer by Jan Simon
on 8 Apr 2013

Do you want `rrad` to be a scalar or a vector of the same size as `c` and `w`? For the later case, you need the elementwies division:

rrad = c ./ w;

The same concerns `Arad = 2*pi*(rrad^2)` also, where you'd need `rrad .^ 2`, and the same for the following vector operations with .* instead of * .

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 2 Comments

## Tobias (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/70064#comment_141813

I'm just about to go to the university, so I don't have time to do an in-depth look at your code, but one thing I see is your mathematical interaction between constants and vectors. I am pretty sure you need to do ./ or .^ etc, if the calculation is be be done on each element of a vector. For example everything that has f included in calculations.

## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/70064#comment_141829

Please post a copy of the error message. Most of all it contains information about the line, where the problem occurs. Then we do not have to guess this line.