Figuring out the most fitting prefix for a vector dataset

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 Comments

What about mode() instead of mean()? Median is better than mean, too.
Yes I tried that we well. But for example when a quantity has the value 10-6 for the first 5 seconds and is then zero for the last 10 seconds I'd still want to get the exponent -6.
What about ignoring the zeros and use the median value as suggested by Adam
median(nonzeros(x))
My values are near zero not exactly zero. I'd probably have to filter out numbers under a certain limit e.g. anything smaller than 1e-24. Because I get values like 10e-80 instead of zeros
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)
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

Sign in to comment.

Answers (1)

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 Comment

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.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2018b

Tags

Asked:

on 28 May 2020

Edited:

on 5 Jun 2020

Community Treasure Hunt

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

Start Hunting!