I want to change the size of a vector's components relative to each other, to a specific number. Help?
1 view (last 30 days)
Show older comments
Okay, so I have written a code that determines the elements of a matrix according to an equation for each of them.
The range of the elements should be between 0 and 31, but the program is not very stable and breaks down at really low numbers for a certain variable. When the variable in question is between 1 and 10, the variable gives me answers that range from -90 to 10. (And no I can't change the variable in any way, it is a given.)
I need to make the minimum number 0 and the maximum number 31, and all the elements of the matrix should be scaled according to that.
For example: if it gives me the matrix [2 -90 10 0 -2 -35] (he max is 10 and the min is -90), I need it to give me a 1X6 matrix that 10=31 and -90=0 and all the other elements range between those numbers relative to each other.
Does anyone have any ideas on how to go about this?
0 Comments
Accepted Answer
Walter Roberson
on 4 Dec 2012
mindata = min(YourData(:));
maxdata = max(Yourdata(:));
mappeddata = (YourData - mindata) ./ (maxdata - mindata) * 31;
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!