MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Asked by Joshua on 4 Dec 2012

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?

Answer by Walter Roberson on 4 Dec 2012

Accepted answer

mindata = min(YourData(:)); maxdata = max(Yourdata(:)); mappeddata = (YourData - mindata) ./ (maxdata - mindata) * 31;

## 0 Comments