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:
scale and truncate

Subject: scale and truncate

From: Konst

Date: 11 Dec, 2010 12:27:04

Message: 1 of 6

I have an electrical signal as a column vector and I plot it. How can I perform a scaling to put data in range [0-1]. Is it the same with truncate to range [0-1]? Does anyone have any idea how to do this?
Thanks for your time!

Subject: scale and truncate

From: Norbert

Date: 11 Dec, 2010 12:38:04

Message: 2 of 6

"Konst " <konstance1@hotmail.com> wrote in message <idvqmo$ppc$1@fred.mathworks.com>...
> I have an electrical signal as a column vector and I plot it. How can I perform a scaling to put data in range [0-1]. Is it the same with truncate to range [0-1]? Does anyone have any idea how to do this?
> Thanks for your time!

I think what you are trying to do, is to normalize your data between 0 and 1. Look at the following link: http://stackoverflow.com/questions/1471370/normalizing-from-0-5-1-to-0-1

Subject: scale and truncate

From: Ahmed Fasih

Date: 11 Dec, 2010 15:57:04

Message: 3 of 6

"Konst " <konstance1@hotmail.com> wrote in message <idvqmo$ppc$1@fred.mathworks.com>...
> I have an electrical signal as a column vector and I plot it. How can I perform a scaling to put data in range [0-1]. Is it the same with truncate to range [0-1]? Does anyone have any idea how to do this?
> Thanks for your time!

x = randn(100,1);
xscaled = interp1([min(x) max(x)], [0 1], x);
xtruncated1 = x .* (x>=0 & x<=1) + 1*(x>1);
xtruncated2 = min(max(x,0), 1);
figure; plot(1:100, [x xscaled xtruncated1 xtruncated2])

xtruncated1 and xtruncated2 will be the same (check norm(xtruncated1 - xtruncated2)), just two different ways to do it. This uses logical indexing [1].

[1] http://blogs.mathworks.com/steve/2008/01/28/logical-indexing/

Subject: scale and truncate

From: Konst

Date: 8 Jan, 2011 10:23:04

Message: 4 of 6

I managed to solve that problem:
 %scale
     Y=(X-min(X))/(max(X)-min(X));
     plot (Y)
     %truncate
index = find( X < 0 );
if (length(index) > 0);
  Y(index) = zeros(length(index),1);
end
index = find( X >= 1 );
if (length(index) > 0)
  Y(index) = ones(length(index),1);
end
index=find(X==0&X==1);
if length(index)>0
    Y(index)=ones(length(index),1);
end
and it works perfectly
Now I use ginput in a loop to select two points from the graph.
How can I use truncate only between these selected points? I tried sth like this:

i=1;
while i>=1;
    [x,y] = ginput(2);
    line(x,y,'Color','g')
 %scale
     Y=(X-min(X))/(max(X)-min(X));
     plot (Y)
     %truncate
     for X=x:y
index = find( X < 0 );
if (length(index) > 0);
  Y(index) = zeros(length(index),1);
end
index = find( X >= 1 );
if (length(index) > 0)
  Y(index) = ones(length(index),1);
end
index=find(X==0&X==1);
if length(index)>0
    Y(index)=ones(length(index),1);
end
end
plot(Y,'m')

That is, I used a for loop but it doesn't seem to do the work? Any ideas?

Subject: scale and truncate

From: Konst

Date: 8 Jan, 2011 20:25:05

Message: 5 of 6

"Konst " <konstance1@hotmail.com> wrote in message <ig9du8$pi3$1@fred.mathworks.com>...
> I managed to solve that problem:
> %scale
> Y=(X-min(X))/(max(X)-min(X));
> plot (Y)
> %truncate
> index = find( X < 0 );
> if (length(index) > 0);
> Y(index) = zeros(length(index),1);
> end
> index = find( X >= 1 );
> if (length(index) > 0)
> Y(index) = ones(length(index),1);
> end
> index=find(X==0&X==1);
> if length(index)>0
> Y(index)=ones(length(index),1);
> end
> and it works perfectly
> Now I use ginput in a loop to select two points from the graph.
> How can I use truncate only between these selected points? I tried sth like this:
>
> i=1;
> while i>=1;
> [x,y] = ginput(2);
> line(x,y,'Color','g')
> %scale
> Y=(X-min(X))/(max(X)-min(X));
> plot (Y)
> %truncate
> for X=x:y
> index = find( X < 0 );
> if (length(index) > 0);
> Y(index) = zeros(length(index),1);
> end
> index = find( X >= 1 );
> if (length(index) > 0)
> Y(index) = ones(length(index),1);
> end
> index=find(X==0&X==1);
> if length(index)>0
> Y(index)=ones(length(index),1);
> end
> end
> plot(Y,'m')
>
> That is, I used a for loop but it doesn't seem to do the work? Any ideas?


Just giving it a push up. Can at least someone point me to the right direction?

Subject: scale and truncate

From: Konst

Date: 9 Jan, 2011 14:27:05

Message: 6 of 6

I also tried Ahmed's way in case I did something wrong:

     %scale and truncate
xscaled=interp1([min(X) max(X)],[0 1], X);
plot (xscaled)
for xscaled=x1:x2
xtruncated1=X.*(X>=0 & X<=1)+1*(X>1);
plot([xtruncated1], 'm')
end
 but it still truncates the whole signal. What am I doing wrong?
Thanks for your time!Any help would be really appreciated.

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