1

I am trying to create a plot using the below code, the plot it produces incorporates values of the x-axis from 0.5-1, however I need the plot to not incorporate this part on the x-axis, from values 0.5-1. I assumed that lines 9 & 10 of the code would exclude this part of the plot, however this is not the case.

Does anyone know what I would write for this part of the plot to be excluded. Thank you!

x = [0:0.01:1];
y = [0:0.01:1];
z = size(101,101);
for j = 1:101;
    for k = 1:101;
        z(j,k)=((x(j))./(0.5-y(k)));
       if z(j,k)>1
           z(j,k)=1;
       elseif z(j,k)<0
           z(j,k)=1;
       end
    end
end
surf(x,y,z)
4
  • 1
    What programming language is this? Please add the appropriate tag to get a better chance for a solution :) Commented Mar 7, 2016 at 13:43
  • Sorry, it is in Matlab. Commented Mar 7, 2016 at 14:10
  • Are we actually speaking about the plot here or do you really mean the data? I assume you know the difference. Why I am asking is that I have hard relate to your approach. Why modify the data to plot a subset of the data, when the subset can be plotted right away? Further setting data points to 1 does not mean these will not be plotted. Commented Mar 7, 2016 at 14:36
  • 1
    Jessica, my advice to you is to elaborate a bit more on the question. Since you have got 2 answers and none of them helps you it is likely that we does not understand what you are after. Commented Mar 8, 2016 at 7:52

2 Answers 2

2

xlim([0 .5]) sets the range to be displayed on the x axis. Use it after your plot command (surf).

Sign up to request clarification or add additional context in comments.

1 Comment

+1 This is the superior approach as there is no modification of the underlying data used to generate the plot.
1
x=[0:0.005:0.5];

This would exclude the data you do not want to see in the plot, but would give you better resolution for your answer.

MWc answer would work as well, but would just exclude the values from 0.5 on.

So it depends on exactly what you wanted to see given your overall problem.

5 Comments

This would exclude the data you do not want to see in the plot, but would give you better resolution for your answer.
When i have tried this it still includes the part from 0.5-1, I have tried MWc's answer, however I would still like the x-axis to go up to 1.
This modificates the data rather than the plot, which is in general not to prefer.
I would just like to exclude the part it plots for values on the x axis which are greater than 0.5, I am not entirely sure how to do this, if i edit the data to only show values for up to 0.5, I will still need the x-axis to go up to 1, so not sure that I can do this.
I am still obtaining the unwanted part of the plot. Not sure what I can do to not include this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.