Figuring out the most fitting prefix for a vector dataset

5 visualizaciones (últimos 30 días)
Bakr Al Beattie
Bakr Al Beattie el 28 de Mayo de 2020
Editada: Bakr Al Beattie el 5 de Jun. de 2020
Hello fellow Matlab users,
I'd like to ask for your advice concerning a numerical topic. So I mainly use Matlab for simulation purposes (electrical circuits). My simulations return vectors containing state variables and power / energy quantities. I'm trying to fully automate a report generation with Matlab code but I'm facing a small problem. I'd like to determine the best prefix for a data set. So for example I get a vector with 1000 values. My initial idea was to get the exponents through a mathematical trick floor(10log10(vect)) and then calculate the mean of the vector containing the exponents, which would give me the mean exponent. From the exponent I can determine the nearest prefix (milli, micro...) . My problem is that some simulations return values with an accuracy of 10e-80 which totally falsifies the mean. So do you guys have any idea on how to basically get the mean exponent of a vector dataset ?
I appreciate all your thoughts and answers
  6 comentarios
Adam Danz
Adam Danz el 29 de Mayo de 2020
So, try it out, then.
median(x(abs(x)>1e20)) % play around with the threshold value.
If that doesn't work, plot the vector of values and show us the results. Something like this would be useful
figure()
subplot(2,1,1)
plot(y,'o-')
subplot(2,1,2)
histogram(y)
Bakr Al Beattie
Bakr Al Beattie el 5 de Jun. de 2020
Editada: Bakr Al Beattie el 5 de Jun. de 2020
Sorry for the late replay but I have been a but busy this past week. So I tried your suggestions and still get the same problem. E.g.
So this is a histogram for one dataset. The corresponding plots:
Specifically, the histogram corresponds to the orange graph in the subplot(3,1,1). But the same problem is still existent in all plots. As can be seen, there is a long period where the data can be zero. Even when I filter out every exponent above abs(10^24), my prefix is still falsified.
Edit: here is the code I use:
function Exp = getExponent(Var)
vecWithExp = abs(floor(log10(abs(Var))));
vecWithExp = vecWithExp(~isinf(vecWithExp));
vecWithExp = vecWithExp(abs(vecWithExp) < 24);
meanExp = median(vecWithExp);
vecWithSign = floor(log10(Var));
sign = round(mean(vecWithSign(~isinf(vecWithSign))));
if isempty(meanExp)
Exp = 0;
else
Exp = sgn(sign)*round(meanExp);
end
end

Iniciar sesión para comentar.

Respuestas (1)

Adam Danz
Adam Danz el 5 de Jun. de 2020
There are no axis labels on the histogram so I'm not sure what it represents. If it represents a distribution of y-values for the orange line in the first subplot, I'd expect a giant bar at x=0 but I don't see that.
I don't undersant what the problem is with taking the median of values greater than some very small number.
m = median(vector(abs(vector)>0.001));
You can play around with the threshold value. If you zoom into the axes using ylim([-.001,.001]) you can see whether all of the undesired data fall into those limits.
  1 comentario
Bakr Al Beattie
Bakr Al Beattie el 5 de Jun. de 2020
Editada: Bakr Al Beattie el 5 de Jun. de 2020
Sorry about the labels. So if you look at my code, you can see that I calculate the exponents and save them in a vector (vecWithExp). The histogram represents the distrubution of the exponents histogram(vecWithExp). The results were obtained using median(vecWithExp(abs(vecWithExp)<24)), which basically filters out all exponents that may falsify the outcome. Please note that I am trying to find a method that works in general cases. In this case my numbers are small. In other simulations these numbers might be large depending on the quantity that I am observing. Additionally, I want to avoid manipulating the threshold everytime I start a simulation and integrate the prefix setting function as a part of the framework, so that it becomes fully automatic. Is there maybe an alternative method? In my histogram, large numbers (6,7,8...) are probably the numbers nearing zero.

Iniciar sesión para comentar.

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by