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

Thread Subject:
changing the range of data in a matrix (similar to mapminmax)

Subject: changing the range of data in a matrix (similar to mapminmax)

From: Adham

Date: 21 May, 2011 03:53:04

Message: 1 of 3

Hi

I have a matrix called Mask and I need to change the current range of data inside this matrix to the range of [1,500] (no instant of matrix should be less than 1 and non should be greater 500). I know that it is possible to use mapminmax but it will convert the range to -1 and 1. Is there any direct way to do this?
I also tried mapminmax(Mask,1,500) but it did not do the job

Thanx
Adham

Subject: changing the range of data in a matrix (similar to mapminmax)

From: Adham

Date: 21 May, 2011 04:12:02

Message: 2 of 3

"Adham " <adham.atyabi@flinders.edu.au> wrote in message <ir7cv0$qcl$1@newscl01ah.mathworks.com>...
> Hi
>
> I have a matrix called Mask and I need to change the current range of data inside this matrix to the range of [1,500] (no instant of matrix should be less than 1 and non should be greater 500). I know that it is possible to use mapminmax but it will convert the range to -1 and 1. Is there any direct way to do this?
> I also tried mapminmax(Mask,1,500) but it did not do the job
>
> Thanx
> Adham

I found this equation in one of the answers, can someone please let me know if I am implementing it in a right way?

y=(ymax-ymin)*(x-ymin)/(xmax-xmin)+1

% Mask is 10*30 and I am going trough each row one by one and rescaling it
for j=1:10
x=Mask(j,:);
 for k=1:size(x,2)
        x(1,k) = (size(d1.data,2)-1)*(x(1,k)-1)/(max(x)-min(x)) + 1;
    end
% it looks like the values are in the right range if you ignore their sign
    Mask2(j,:)=abs(x(:))';
end

Cheers
Adham

Subject: changing the range of data in a matrix (similar to mapminmax)

From: Roger Stafford

Date: 21 May, 2011 06:56:05

Message: 3 of 3

"Adham " <adham.atyabi@flinders.edu.au> wrote in message <ir7e2i$t12$1@newscl01ah.mathworks.com>...
> "Adham " <adham.atyabi@flinders.edu.au> wrote in message <ir7cv0$qcl$1@newscl01ah.mathworks.com>...
> > Hi
> >
> > I have a matrix called Mask and I need to change the current range of data inside this matrix to the range of [1,500] (no instant of matrix should be less than 1 and non should be greater 500). I know that it is possible to use mapminmax but it will convert the range to -1 and 1. Is there any direct way to do this?
> > I also tried mapminmax(Mask,1,500) but it did not do the job
> >
> > Thanx
> > Adham
>
> I found this equation in one of the answers, can someone please let me know if I am implementing it in a right way?
>
> y=(ymax-ymin)*(x-ymin)/(xmax-xmin)+1
>
> % Mask is 10*30 and I am going trough each row one by one and rescaling it
> for j=1:10
> x=Mask(j,:);
> for k=1:size(x,2)
> x(1,k) = (size(d1.data,2)-1)*(x(1,k)-1)/(max(x)-min(x)) + 1;
> end
> % it looks like the values are in the right range if you ignore their sign
> Mask2(j,:)=abs(x(:))';
> end
>
> Cheers
> Adham
- - - - - - - - - - -
  According to the thread at:

 http://www.mathworks.com/matlabcentral/newsreader/view_thread/304452

a bug has been reported in 'mapminmax' for version matlabr2010b, which is probably why yours didn't work.

  Also it looks as though you copied the document formula incorrectly. It should read:

 y = (ymax-ymin)*(x-xmin)/(xmax-xmin) + ymin;

with ymax and ymin being your 500 and 1, respectively, and where xmax and xmin are column vectors of the maximum and minimum values along each of the rows of x.

  You can implement the above formula without using for-loops if you make use of matlab's 'bsxfun' function:

 t = min(x,[],2);
 y = (ymax-ymin)*bsxfun(@rdivide,bsxfun(@minus,x,t),max(x,[],2)-t)+ymin;

This only works if none of the rows of x have constant values - otherwise you will get some NaNs.

  You can test the results by checking that each row of y will attain both the values ymax and ymin somewhere within the row and that nowhere do y values fall outside that range.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us