How to correct matrix dimension disagree error
2 views (last 30 days)
Show older comments
Samuel Suakye
on 28 Mar 2020
Commented: Samuel Suakye
on 16 Apr 2020
figure
clear;
clc;
v = 1.0;
n=[0.00 0.10 0.12 0.18];
u = linspace(0,2);
%%
for i = 1:length(n)
sigma = ((1i.*u-1-v.^2)./(v.^2-u.^2 +1-2i.*u)).*(1./(v.^2 +1));
sigmapri = n*((1i.*u-1-v.^2)./((1+n).^2 +v.^2).*(v.^2-u.^2 +1-2i.*u)).*(1-(v./(v.^2 +1)));
w = sigma + sigmapri;
plot(u, real(w))
end
%%
xlabel('\omega*\tau')
ylabel('\sigma(\omega)/\sigma_o')
4 Comments
Accepted Answer
Image Analyst
on 28 Mar 2020
I think you're looking for this:
hFig = figure
clc;
v = 1.0;
n=[0.00 0.10 0.12 0.18];
u = linspace(0,2, 30); % However many you want.
legendStrings = cell(length(n), 1);
for k1 = 1:length(n)
thisN = n(k1);
for k2 = 1 : length(u)
thisU = u(k2);
sigma = ((1i.*thisU-1-v.^2)./(v.^2-thisU.^2 +1-2i.*thisU)).*(1./(v.^2 +1));
sigmapri = thisN * ((1i.*thisU-1-v.^2)./((1+thisN).^2 +v.^2).*(v.^2-thisU.^2 +1-2i.*thisU)).*(1-(v./(v.^2 +1)));
w(k2) = sigma + sigmapri;
end
legendStrings{k1} = sprintf('n = %.2f', thisN);
plot(u, real(w), '.-', 'LineWidth', 2, 'MarkerSize', 15);
hold on;
drawnow;
end
grid on;
fontSize = 20;
xlabel('\omega*\tau', 'FontSize', fontSize)
ylabel('\sigma(\omega)/\sigma_o', 'FontSize', fontSize)
title('\sigma(\omega)/\sigma_o vs. \omega*\tau', 'FontSize', fontSize)
legend(legendStrings, 'Location', 'northwest');
% Maximize the figure window.
hFig.WindowState = 'maximized';
4 Comments
More Answers (1)
the cyclist
on 28 Mar 2020
You are effectively trying to do this operation in your code:
n * u
where n is a 1x4 matrix, and u is a 1x100 matrix.
That won't work, as either a matrix multiplication or as an element-by-element multiplication. What do you expect from that?
See Also
Categories
Find more on Startup and Shutdown 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!