MATLAB Viewing Matlab Plot and Vectors in Workspace for Beginners"

  • Thread starter Thread starter kususe
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary
The discussion revolves around creating and manipulating plots in MATLAB, specifically focusing on how to visualize data from vectors "tv" and "fo" while ensuring these vectors are accessible in the workspace. A suggestion is made to return the plot handle as an output variable, allowing users to retrieve the data using figure commands. Additionally, the conversation shifts to performing a Fourier transform on the power vs. time data generated by a semiconductor laser simulation. Users express difficulties in obtaining a frequency graph using the FFT function, with a recommendation to refer to MATLAB's documentation for examples. The importance of correctly implementing the FFT function and ensuring proper data handling is emphasized, as some users report not achieving the desired graphical output.
kususe
Messages
22
Reaction score
0
Code:
Ts=Nss:Nss:length(s);

hold on

plot(tv(Ts),fo(Ts),'or');

hold off

grid on

This is the last part of my Matlab macro.
I see that it creates a plot using two vectors called "tv" and "fo".
I would like to see the plot and this vectors too in my workspace on Matlab.
May I use a cycle?

Thank you in advance
 
Physics news on Phys.org
If that is a subfunction and you want to access the variables outside of the function, you can jreturn them as an output variable.

An easier way to do it (that I think will fit your needs better) is by using the Figure you created to access the data. in Matlab, figures are like global variables, and you can access them and their properties in any workspace as long as you have access to the figure's handle (which is a double).

in the function, when you plot use:
Code:
p = plot(tv(Ts),fo(Ts),'or');

and return p as an output variable. you can now access the figure you created and its properties (including the tv and fo vectors) by using the appropriate figure commands. for example, to get tv from the plot with the handle p would be something like this:

Code:
get(p,'xdata');
 
i have written the code for power vs time of a semiconductor laser for my homework. if i Fourier transform it...wdnt i get the pwer vs freq graph|?? how will i Fourier transform it??
i use y=fft(p) but i am not getting it...pleasez help...i have given the code

mmm=0;
for nW=[1 3 5]
mmm=mmm+1;
mm=0;
Lam=405e-9;
q=1.6e-19;
alpha=1.2;
Tn=3e-9;
Tp=6.5e-12;
G0=9.0e-6;
N0 = 1.2e15;
h=6.6e-34;
c=3e8;
Gamma=.208;
beta=4.0e-4;
epsilon=3.4e-17;
Va=10.64e-11;

for I =.1e-3:.1e-3:3.97e-3;


mm=mm+1;
tini=0;
tfin=7e-9;
dt=1e-12;
m=0;
N(1)=0;
S(1)=0;
D(1)=0;
for t=tini:dt:tfin
m=m+1;
delN=I/(q*Va)-N(m)/Tn-G0*(N(m)-N0)*S(m)/(1+epsilon*S(m));
delS=-S(m)/Tp+Gamma*beta*N(m)/Tn+Gamma*G0*(N(m)-N0)*S(m)/(1+epsilon*S(m));
delD=.5*alpha*(Gamma*(N(m)-N0)-(1/Tp));

N(m+1)=N(m)+dt*delN;
S(m+1)=S(m)+dt*delS;
D(m+1)=D(m)+dt*delD;
P(m+1)=1000*Va*S(m)*.85*h*c/(Lam*2*Gamma*Tp);
tt(m+1)=t;

end
II(mm)=I*1e3;
Po(mmm,mm)=sum(P(1:4000))/4000;
N1(mmm,mm)=sum(N(1:4000)/4000);
S1(mmm,mm)=sum(S(1:4000)/4000);
D1(mmm,mm)=sum(D(1:4000)/4000);


Po1(mmm,:)=P;
Nt(mmm,:)=N;
St(mmm,:)=S;
Dt(mmm,:)=D;
end
end



figure(3)
plot(tt,Po1);
xlabel('Time (ns)')
ylabel('Output power (mW)')
title('Output power Vs Time')
 
i did use that fft function . . but i don't get any results..i mean no graph...
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
8
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K