Effacer les filtres
Effacer les filtres

how to plot a bounding min/max function around the output of a Monte Carlo simulation?

2 vues (au cours des 30 derniers jours)
Matt
Matt le 14 Mai 2016
Commenté : Image Analyst le 15 Mai 2016
Consider the following Matlab code that generates and plots 3 random functions that are sampled at different timestamps within the time period [0,1]. Note that the timestamps for each sample are different.
if true
% code
end % code
t=rand(30,3);
st=zeros(30,3);
for k=1:3
st(:,k)=sort(t(:,k));
end
d=2-2*rand(30,3);
figure; plot(st(:,1),d(:,1)); hold on;
for k=2:3
plot(st(:,k),d(:,k));
end
grid minor;
I want to calculate and plot the minimum and the maximum functions.
Please note
min(d')' does not find the minimum at all the timestamps. Any idea please?
  1 commentaire
Image Analyst
Image Analyst le 14 Mai 2016
Do you want the min value of the data for each time, st, value? This would just be the data sorted since there is just one value at each time stamp. OR do you want the data going along the very bottom-most line that gets plotted?

Connectez-vous pour commenter.

Réponses (2)

Mohamed Eljali
Mohamed Eljali le 14 Mai 2016
Modifié(e) : Mohamed Eljali le 14 Mai 2016
% code
clc;
clear all;
close all;
t=rand(30,3);
st=zeros(30,3);
for k=1:3
st(:,k)=sort(t(:,k));
end
d=2-2*rand(30,3);
figure; plot(st(:,1),d(:,1)); hold on;
for k=2:3
plot(st(:,k),d(:,k));
end
hold on;
grid minor;
%Let us assume minimum=inf and their location= (0,0)
minimum_value=Inf;
i1=0;
j1=0;
%Let us assume maximum=-inf and their location= (0,0)
maximum_value=-Inf;
i2=0;
j2=0;
for k=2:3
for i=1:30
% Finding or updating mimimum value and their location
if minimum_value> d(i,k)
minimum_value=d(i,k);
i1=i;
j1=k;
end
% Finding or updating maximum value and their location
if maximum_value<d(i,k)
maximum_value=d(i,k);
i2=i;
j2=k;
end
end
end
%Finally plotting minimum and maximum values in the graph
plot(st(i1,j1),d(i1,j1),'*r','Linewidth',3); hold on
plot(st(i2,j2),d(i2,j2),'*k','Linewidth',3);
  1 commentaire
Image Analyst
Image Analyst le 15 Mai 2016
If all he wanted was the global min and global max, he would simply use min() and max() like this:
[minDValue, index] = min(d(:))
stAtMinD = st(index)
[maxDValue, index] = max(d(:))
stAtMaxD = st(index)
It's simpler than the for loops because it calculates the min and location for you - you don't have to do it yourself in a for loop.
I interpreted this "min(d')' does not find the minimum at all the timestamps" to indicate that he wanted the min for all times, not just the global min. Like he wants the lowest line going across the timeline, not just one single point. That's a lot tougher to get - he'll have to increase resolution to get the lines everywhere. If he doesn't want it everywhere but only at the discrete locations of st, then that's trivial - just sort st and d and you're done. Since the timestamps are unique, there is only one value for each timestamp, and so that value is both the max and the min.

Connectez-vous pour commenter.


Mohamed Eljali
Mohamed Eljali le 14 Mai 2016

Catégories

En savoir plus sur Loops and Conditional Statements 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!

Translated by