Viewing Matlab Plot and Vectors in Workspace: A Guide for Beginners"

  • MATLAB
  • Thread starter kususe
  • Start date
  • Tags
    Matlab
In summary: I am sorry to hear that you are having difficulty using the fft function. I would recommend trying to find a different example or tutorial on the website to get started.
  • #1
kususe
22
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
  • #2
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');
 
  • #3
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')
 
  • #5
i did use that fft function . . but i don't get any results..i mean no graph...
 

1. How do I view a plot in Matlab?

To view a plot in Matlab, you can use the plot function with the desired data and then use the show command to display the plot.

2. What is the workspace in Matlab?

The workspace in Matlab is where all of your variables and data are stored. It is essentially a storage space for your code to access and manipulate data.

3. How do I view vectors in the workspace?

To view vectors in the workspace, you can use the disp command followed by the name of the vector variable. This will display the values of the vector in the command window.

4. Can I customize the appearance of plots in Matlab?

Yes, you can customize the appearance of plots in Matlab by using various options and commands such as title, xlabel, ylabel, legend, and more.

5. Is it possible to save my plots and vectors in the workspace?

Yes, you can save your plots and vectors in the workspace by using the save command. This will create a .mat file containing the saved variables that can be loaded and accessed in future Matlab sessions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
569
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
Back
Top