How to not draw some points of an interval( hmax and hmin )

조회 수: 1 (최근 30일)
Antonella
Antonella 2013년 10월 11일
댓글: Antonella 2013년 10월 15일
I have this function but i have to finish it. I have to say to matlab to not draw the points of the graph between hmax and hmin Can someone help me???
h = max(y); hmax = (percT/100)*h; hmin = (percB)/100*h;
for i=1:size(y,1) if y(i)> hmax y(i) = hmax; else if y(i)< hmin y(i) = hmin;
else.....how i have to finish???
Many thanks in advance!!!
  댓글 수: 2
sixwwwwww
sixwwwwww 2013년 10월 11일
Dear Antonella, Can you share complete code because information about variables like "y", "percT", "percB" and also which value you want to plot?
Antonella
Antonella 2013년 10월 15일
percT is 60 an percB is 30. the variable y rapresents the high of the graph (the graph is about a hand-written word). So i have to remove the middle part of this graph(word) so every point between 30-60% of the total high. Hope this is clearer! Many thanks in advance!

댓글을 달려면 로그인하십시오.

답변 (1개)

Jonathan LeSage
Jonathan LeSage 2013년 10월 14일
You can use logical indexing to remove any values greater than and less than the desired bounds.
% Defining some arbitrary data
x = 0:0.05:2*pi;
y = sin(x);
% Defining some arbitrary bounds
hmax = 0.5;
hmin = -0.5;
y_bounded = y;
% Using logical indexing to replace all values > hmax with NaN
% When plotting, MATLAB ignores values that are defined as NaN
y_bounded(y_bounded > hmax) = NaN;
y_bounded(y_bounded < hmin) = NaN;
% Plot Results
plot(x,y,x,y_bounded,'o');
grid on;
legend('Orignal Data','Bounded Data');
Hope this helps!
  댓글 수: 1
Antonella
Antonella 2013년 10월 15일
thanks really much for the answer! I'll try and check if it's work! Anyway i have to use if, else if ecc...how i can translate what you wrote me in this way? is there the possibility to do this or not? Really many thanks ;)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by