![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172598/image.png)
To draw an intensity curve with Matlab
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Pouyan Msgn
il 16 Feb 2017
Commentato: Star Strider
il 21 Feb 2017
I have a function :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160804/image.gif)
And I want to draw the intensity curve :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160805/image.png)
where T has values : 600, 800, 1000, 1100 And λ:(0,10*^-5] I have to use max function with two values and the solution must not consist of repeating four times of similar snippets of code, one for each curve.The image should be stylish. For example. so the texts may not cut curves, but neatly placed just above the maximum point.
Can somebody please help me how I can start ?! I must say I'm a beginner too
0 Commenti
Risposta accettata
Star Strider
il 16 Feb 2017
Modificato: Star Strider
il 16 Feb 2017
This should get you started.
Since this seems to be a homework problem, I will let you determine how to locate and plot the peaks. See the documentation for the various functions and the section on Anonymous Functions in Function Basics.
The Code —
f = @(L,T) 3.7E-16 ./ (L.^5 .* (exp(0.014 ./ (L .* T)) -1));
T = [600, 800, 1000, 1100];
L = linspace(0, 1E-5);
[Tm,Lm] = meshgrid(T, L);
fm = f(Lm,Tm);
figure(1)
plot(L, fm)
grid
xlabel('\lambda')
ylabel('\itF\rm(\it\lambda,T\rm)')
lgndcell = regexp(sprintf('T = %d\n',T), '\n', 'split')
legend(lgndcell(1:end-1), 'Location','NE')
Also see the documentation for the text function. You will need that to label the peaks. Specifically note the name-value pair arguments so you can position the labels correctly with respect to the points you plotted at the peaks.
The Plot —
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172598/image.png)
EDIT — Added plot my code produces.
3 Commenti
Star Strider
il 17 Feb 2017
My pleasure.
The meshgrid call creates a matching matrix of values for each argument vector. The function then calculates a resulting matrix for both argument matrices, making it easier to calculate and plot them.
The plot function automatically chooses the correct dimension of the ‘fm’ matrix to plot, depending on the x-vector.
The meshgrid call eliminates an explicit loop, although there are likely implicit loops in the way the ‘f’ function is evaluated.
You could also plot the function as:
figure(2)
surfc(Tm, Lm, fm)
grid on
if you want to see what it looks like in 3D.
Più risposte (2)
Pouyan Msgn
il 18 Feb 2017
Modificato: Pouyan Msgn
il 18 Feb 2017
7 Commenti
Star Strider
il 21 Feb 2017
You need to specify a format descriptor to tell sprintf to print a numerical value. Your largest temperature values are 4 digits, so I chose '%4d' to output a 4-digit integer for all of them (using leading spaces for the values with less than 4 digits). See the documentation for sprintf for details on specifying format descriptors.
The '\n' is a ‘newline’ character that would normally produce a carriage return and linefeed sequence with, for example, fprintf. Here, I use it as a separator that regexp will recognise as the end-of-string indicator to do the split. See the documentation on regexp for details.
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!