如何在MATLAB中绘制图表?

时间:2016-11-06 13:58:31

标签: matlab matlab-figure waveform electronics wave

我正在尝试使用MATLAB绘制给定相位常量的 - 图表,但是虽然我查看了很多网页,但是没有类似的示例绘图 - 图表MATLAB。能否请您解释一下如何着手解决这个问题?任何帮助都会非常感激。

图表范围: =10ℎ-10

w:角度频率

wc:一个恒定的角频率

1st的参数: 1 = 0.2 *,2 = 0.4 *,3 = 0.6 *,4 = 0.8 *,ɛ1= 1 *ɛ0,μ=μ0

1st的参数: a1 = 0.08636cm,a2 = 0.8636cm,a3 = 2.286cm,a4 = 29.21cm,ɛ1= 1 *ɛ0,μ=μ0

enter image description here

1 个答案:

答案 0 :(得分:2)

正如OP所问,这是一种Matlab代码。 我假设在范围[1,100]中绘制了B与w的图(但值可以更改) 第一种情况有wc有3种不同的情况,4种不同的B(B1,B2,B3和B4)图将以四种不同颜色映射

    %constant inizialization
    mu = 1.2566E-6;
    e = 1;
    start_f = 10000; %10 MHz start frequency range
    end_f = 10000000; %10 GHz end frequency range 
    step = 10 %plot the function every "step" Hz (ONLY INTEGER NUMBERS ALLOWED)
    k = 1;
    % function of B example: B = w*sqrt(mu*e)*sqrt(1-((wc^2)/w));

    %vectors initialization to avoid the "consider preallocation" Matlab not-critical warning
    range_f = ceil((end_f - start_f)/step) + 1;
    w = zeros(range_f);
    B1 = zeros(range_f);
    B2 = zeros(range_f);
    B3 = zeros(range_f);
    B4 = zeros(range_f);

    for i=start_f:step:end_f %from 10 MHz to 10 GHz with steps of 1 Hz
    %store i in the i-cell of vector w
      w(k) = i;
%values that need to be updated every time
      w1 = 0.2*w(i);
      w2 = 0.4*w(i); 
      w3 = 0.6*w(i);
      w4 = 0.8*w(i); 
%four different results of B
      B1(i) = w(i)*sqrt(mu*e)*sqrt(1-((w1^2)/w(i)));
      B2(i) = w(i)*sqrt(mu*e)*sqrt(1-((w2^2)/w(i)));
      B3(i) = w(i)*sqrt(mu*e)*sqrt(1-((w3^2)/w(i)));
      B4(i) = w(i)*sqrt(mu*e)*sqrt(1-((w4^2)/w(i)));

      k = k+1;
    end
%plot the 4 lines    
    plot(w,B1,'r') %red line of B1 = f(w) 
    hold on
    plot(w,B2,'g') %green line of B2 = f(w) 
    hold on
    plot(w,B3,'b') %blue line of B3 = f(w) 
    hold on
    plot(w,B4,'k') %black line of B4 = f(w) 

4个不同的案例必须用4个图表来表示(在这个例子中,它们已被覆盖)。

最后一种表示法可以用同样的方式完成(你有4个常数参数a1,a2等),这个时间不依赖于w。所以

  B1a(i) = sqrt((w(i)^2)*mu*e - ((pi^2)/a1)));
  B2a(i) = sqrt((w(i)^2)*mu*e - ((pi^2)/a1)));
  B3a(i) = sqrt((w(i)^2)*mu*e - ((pi^2)/a1)));
  B4a(i) = sqrt((w(i)^2)*mu*e - ((pi^2)/a1)));

如果您遇到某些错误(由于"快速"写入),请在评论中报告,我将更正并更新代码