need plotting help with matrix and loops

1 visualización (últimos 30 días)
neil whitesell
neil whitesell el 23 de Nov. de 2020
Comentada: neil whitesell el 30 de Nov. de 2020
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 comentario
neil whitesell
neil whitesell el 23 de Nov. de 2020
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

Iniciar sesión para comentar.

Respuestas (1)

Rohit Pappu
Rohit Pappu el 26 de Nov. de 2020
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

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by