Viewing Matlab Plot and Vectors in Workspace for Beginners"

  • Context: MATLAB 
  • Thread starter Thread starter kususe
  • Start date Start date
  • Tags Tags
    Matlab
Click For Summary

Discussion Overview

The discussion revolves around using MATLAB for plotting data and accessing vectors in the workspace, as well as performing Fourier transforms on data related to a semiconductor laser. Participants seek assistance with specific coding issues and conceptual understanding.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant shares a MATLAB code snippet for plotting and asks how to view the plot and vectors in the workspace, suggesting the use of a cycle.
  • Another participant suggests returning the plot handle as an output variable to access the data associated with the plot, indicating that figures can be treated like global variables in MATLAB.
  • A different participant describes their homework involving the power vs. time of a semiconductor laser and questions how to perform a Fourier transform on the data, expressing confusion about not obtaining results with the FFT function.
  • One participant points out that the Fourier transform question should be in a separate thread but provides a link to an example of FFT code from the MathWorks website.
  • A later reply indicates that the participant did use the FFT function but is still not getting any results or graphs.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and success with MATLAB functions, particularly regarding the use of the FFT function and accessing plot data. There is no consensus on the effectiveness of the FFT approach or the best method to visualize data in the workspace.

Contextual Notes

Participants mention specific coding issues and functions without resolving the underlying assumptions or steps necessary for successful implementation. The discussion includes various approaches to accessing plot data and performing Fourier transforms, but lacks clarity on the conditions for success.

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 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K