need plotting help with matrix and loops

2 次查看(过去 30 天)
i have a program that spits out a 101 row complex matrix, but i need to retrieve only the 50th row (one less than the 'middle') and save it into the plot, then re-do the loop to gather the same vallue with a different variable each time, to plot the change in the result. i am new to matlab and need some help fixing this error please
the variable i am snatching is 'cur' and i'd like to plot it on y axis with 'imp' on the x-axis.
(if you're curious this is an antenna program to graph the impedance and current as the 'thickness' of the antenna changes)
close all
clc
addpath c:\antennas\ewa;
l=.68;
a=(.00002);
ker='a';
basis='d';
E=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
x=(0:1:100);
for a=.00002:.00001:.01
pfield(l,a,E,ker,basis);
cur=abs(ans(50))
imp=100/cur
plot(imp,cur);
hold on
end
hold off
  1 个评论
neil whitesell
neil whitesell 2020-11-23
the pfield() program spits out a complex matrix of the same size as the input 'E', the bit where i specify 'ans' is the output of that pprogram

请先登录,再进行评论。

回答(1 个)

Rohit Pappu
Rohit Pappu 2020-11-26
Minor refactoring of the above code
close all
clc
clf %%Clear the figure window
addpath c:\antennas\ewa;
l=.68;
a=(.00002);
ker='a';
basis='d';
E=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100000,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
x=(0:1:100);
hold on
for a=.00002:.00001:.01
output = pfield(l,a,E,ker,basis); %% Using ans in a script is not a good idea
cur=abs(output(50));
imp=100/cur;
plot(imp,cur,'Marker','*'); %% Plots each point as an asterix *
end
hold off

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by