How to correct matrix dimension disagree error
    6 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
    Samuel Suakye
 le 28 Mar 2020
  
    
    
    
    
    Commenté : Samuel Suakye
 le 16 Avr 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 commentaires
Réponse acceptée
  Image Analyst
      
      
 le 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 commentaires
Plus de réponses (1)
  the cyclist
      
      
 le 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?
Voir également
Catégories
				En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!