How to correct matrix dimension disagree error
2 次查看(过去 30 天)
显示 更早的评论
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')
采纳的回答
Image Analyst
2020-3-28
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';
更多回答(1 个)
the cyclist
2020-3-28
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!