![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172598/image.png)
To draw an intensity curve with Matlab
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pouyan Msgn
le 16 Fév 2017
Commenté : Star Strider
le 21 Fév 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 commentaires
Réponse acceptée
Star Strider
le 16 Fév 2017
Modifié(e) : Star Strider
le 16 Fév 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 commentaires
Star Strider
le 17 Fév 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.
Plus de réponses (2)
Pouyan Msgn
le 18 Fév 2017
Modifié(e) : Pouyan Msgn
le 18 Fév 2017
7 commentaires
Star Strider
le 21 Fév 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.
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!