Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

I want to change the size of a vector's components relative to each other, to a specific number. Help?

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?

0 Comments

Joshua

Products

1 Answer

Answer by Walter Roberson on 4 Dec 2012
Accepted answer
mindata = min(YourData(:));
maxdata = max(Yourdata(:));
mappeddata = (YourData - mindata) ./ (maxdata - mindata) * 31;

1 Comment

Joshua on 4 Dec 2012

Thank you! That worked beautifully

Walter Roberson

Contact us