Inverse of 1D vector Matlab [closed]












0














I have 1D vector. For example: y=[0.2 0.9 1.0 1.0]. I can plot it with plot(y) to get a graph of y(x) where x values are just indices [1, 2, 3, 4].



Now, instead of x values being just indices, I want to map them to [0,1] range: x = linspace(0,1,length(y)). I get: x=[0 0.3333 0.6667 1.000].



I can now make a graph with plot(x,y):



enter image description here



Now, however, I want an inverse graph, so I make a plot with plot(y,x):
enter image description here



I want to be able to now use plot(x) to get the same shape as above. However, if I use plot(x), as expected, I just get a straight line.



How to transform x in such a way that plot(x) will give the same shape as plot(y,x)?



Upd.: If I try just 1./x:
enter image description here










share|improve this question















closed as unclear what you're asking by Wolfie, Dev-iL, M-M, Makyen, Paul Roub Nov 20 '18 at 14:58


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Why don't you want to use plot(y,x)? I almost never use plot(x), even when I want integer indices (I'd use plot(1:numel(x),x)), because of controlabillity of the function.
    – Adriaan
    Nov 19 '18 at 13:07










  • @Adriaan Because I am not going to plot it. The plot was used only as an example, because I don't know how to better explain what I mean by "inverse of 1D vector". In general, I need to use is as a transformation vector and multiply it element-wise with another 1D vector.
    – Valeria
    Nov 19 '18 at 13:09








  • 1




    Then 1./x would suffice. The plot just creates confusion, since the x locations of corresponding y values also get changed (e.g. the 2nd value of the first plot is at x==1/3, whereas in the second plot it's at x==0.9), which means you need 2 numbers per point, as opposed to the single one you're apparently after, judging your comment.
    – Adriaan
    Nov 19 '18 at 13:17










  • @Adriaan if I just get 1./x, this gives me completely different y-axis values from the ones I am looking for (added to the original question).
    – Valeria
    Nov 19 '18 at 13:25










  • fliplr for row-vectors then? That's not the inverse, but rather 'read in opposite direction'. The images don't help a thing; all they do is confuse me. Can you just show in numbers what you want; i.e. first your x,y pair as you have it now, then what you get using your method, and finally what you want to obtain? Just in numbers?
    – Adriaan
    Nov 19 '18 at 13:29


















0














I have 1D vector. For example: y=[0.2 0.9 1.0 1.0]. I can plot it with plot(y) to get a graph of y(x) where x values are just indices [1, 2, 3, 4].



Now, instead of x values being just indices, I want to map them to [0,1] range: x = linspace(0,1,length(y)). I get: x=[0 0.3333 0.6667 1.000].



I can now make a graph with plot(x,y):



enter image description here



Now, however, I want an inverse graph, so I make a plot with plot(y,x):
enter image description here



I want to be able to now use plot(x) to get the same shape as above. However, if I use plot(x), as expected, I just get a straight line.



How to transform x in such a way that plot(x) will give the same shape as plot(y,x)?



Upd.: If I try just 1./x:
enter image description here










share|improve this question















closed as unclear what you're asking by Wolfie, Dev-iL, M-M, Makyen, Paul Roub Nov 20 '18 at 14:58


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Why don't you want to use plot(y,x)? I almost never use plot(x), even when I want integer indices (I'd use plot(1:numel(x),x)), because of controlabillity of the function.
    – Adriaan
    Nov 19 '18 at 13:07










  • @Adriaan Because I am not going to plot it. The plot was used only as an example, because I don't know how to better explain what I mean by "inverse of 1D vector". In general, I need to use is as a transformation vector and multiply it element-wise with another 1D vector.
    – Valeria
    Nov 19 '18 at 13:09








  • 1




    Then 1./x would suffice. The plot just creates confusion, since the x locations of corresponding y values also get changed (e.g. the 2nd value of the first plot is at x==1/3, whereas in the second plot it's at x==0.9), which means you need 2 numbers per point, as opposed to the single one you're apparently after, judging your comment.
    – Adriaan
    Nov 19 '18 at 13:17










  • @Adriaan if I just get 1./x, this gives me completely different y-axis values from the ones I am looking for (added to the original question).
    – Valeria
    Nov 19 '18 at 13:25










  • fliplr for row-vectors then? That's not the inverse, but rather 'read in opposite direction'. The images don't help a thing; all they do is confuse me. Can you just show in numbers what you want; i.e. first your x,y pair as you have it now, then what you get using your method, and finally what you want to obtain? Just in numbers?
    – Adriaan
    Nov 19 '18 at 13:29
















0












0








0







I have 1D vector. For example: y=[0.2 0.9 1.0 1.0]. I can plot it with plot(y) to get a graph of y(x) where x values are just indices [1, 2, 3, 4].



Now, instead of x values being just indices, I want to map them to [0,1] range: x = linspace(0,1,length(y)). I get: x=[0 0.3333 0.6667 1.000].



I can now make a graph with plot(x,y):



enter image description here



Now, however, I want an inverse graph, so I make a plot with plot(y,x):
enter image description here



I want to be able to now use plot(x) to get the same shape as above. However, if I use plot(x), as expected, I just get a straight line.



How to transform x in such a way that plot(x) will give the same shape as plot(y,x)?



Upd.: If I try just 1./x:
enter image description here










share|improve this question















I have 1D vector. For example: y=[0.2 0.9 1.0 1.0]. I can plot it with plot(y) to get a graph of y(x) where x values are just indices [1, 2, 3, 4].



Now, instead of x values being just indices, I want to map them to [0,1] range: x = linspace(0,1,length(y)). I get: x=[0 0.3333 0.6667 1.000].



I can now make a graph with plot(x,y):



enter image description here



Now, however, I want an inverse graph, so I make a plot with plot(y,x):
enter image description here



I want to be able to now use plot(x) to get the same shape as above. However, if I use plot(x), as expected, I just get a straight line.



How to transform x in such a way that plot(x) will give the same shape as plot(y,x)?



Upd.: If I try just 1./x:
enter image description here







matlab plot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 13:24

























asked Nov 19 '18 at 12:59









Valeria

10410




10410




closed as unclear what you're asking by Wolfie, Dev-iL, M-M, Makyen, Paul Roub Nov 20 '18 at 14:58


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Wolfie, Dev-iL, M-M, Makyen, Paul Roub Nov 20 '18 at 14:58


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • Why don't you want to use plot(y,x)? I almost never use plot(x), even when I want integer indices (I'd use plot(1:numel(x),x)), because of controlabillity of the function.
    – Adriaan
    Nov 19 '18 at 13:07










  • @Adriaan Because I am not going to plot it. The plot was used only as an example, because I don't know how to better explain what I mean by "inverse of 1D vector". In general, I need to use is as a transformation vector and multiply it element-wise with another 1D vector.
    – Valeria
    Nov 19 '18 at 13:09








  • 1




    Then 1./x would suffice. The plot just creates confusion, since the x locations of corresponding y values also get changed (e.g. the 2nd value of the first plot is at x==1/3, whereas in the second plot it's at x==0.9), which means you need 2 numbers per point, as opposed to the single one you're apparently after, judging your comment.
    – Adriaan
    Nov 19 '18 at 13:17










  • @Adriaan if I just get 1./x, this gives me completely different y-axis values from the ones I am looking for (added to the original question).
    – Valeria
    Nov 19 '18 at 13:25










  • fliplr for row-vectors then? That's not the inverse, but rather 'read in opposite direction'. The images don't help a thing; all they do is confuse me. Can you just show in numbers what you want; i.e. first your x,y pair as you have it now, then what you get using your method, and finally what you want to obtain? Just in numbers?
    – Adriaan
    Nov 19 '18 at 13:29




















  • Why don't you want to use plot(y,x)? I almost never use plot(x), even when I want integer indices (I'd use plot(1:numel(x),x)), because of controlabillity of the function.
    – Adriaan
    Nov 19 '18 at 13:07










  • @Adriaan Because I am not going to plot it. The plot was used only as an example, because I don't know how to better explain what I mean by "inverse of 1D vector". In general, I need to use is as a transformation vector and multiply it element-wise with another 1D vector.
    – Valeria
    Nov 19 '18 at 13:09








  • 1




    Then 1./x would suffice. The plot just creates confusion, since the x locations of corresponding y values also get changed (e.g. the 2nd value of the first plot is at x==1/3, whereas in the second plot it's at x==0.9), which means you need 2 numbers per point, as opposed to the single one you're apparently after, judging your comment.
    – Adriaan
    Nov 19 '18 at 13:17










  • @Adriaan if I just get 1./x, this gives me completely different y-axis values from the ones I am looking for (added to the original question).
    – Valeria
    Nov 19 '18 at 13:25










  • fliplr for row-vectors then? That's not the inverse, but rather 'read in opposite direction'. The images don't help a thing; all they do is confuse me. Can you just show in numbers what you want; i.e. first your x,y pair as you have it now, then what you get using your method, and finally what you want to obtain? Just in numbers?
    – Adriaan
    Nov 19 '18 at 13:29


















Why don't you want to use plot(y,x)? I almost never use plot(x), even when I want integer indices (I'd use plot(1:numel(x),x)), because of controlabillity of the function.
– Adriaan
Nov 19 '18 at 13:07




Why don't you want to use plot(y,x)? I almost never use plot(x), even when I want integer indices (I'd use plot(1:numel(x),x)), because of controlabillity of the function.
– Adriaan
Nov 19 '18 at 13:07












@Adriaan Because I am not going to plot it. The plot was used only as an example, because I don't know how to better explain what I mean by "inverse of 1D vector". In general, I need to use is as a transformation vector and multiply it element-wise with another 1D vector.
– Valeria
Nov 19 '18 at 13:09






@Adriaan Because I am not going to plot it. The plot was used only as an example, because I don't know how to better explain what I mean by "inverse of 1D vector". In general, I need to use is as a transformation vector and multiply it element-wise with another 1D vector.
– Valeria
Nov 19 '18 at 13:09






1




1




Then 1./x would suffice. The plot just creates confusion, since the x locations of corresponding y values also get changed (e.g. the 2nd value of the first plot is at x==1/3, whereas in the second plot it's at x==0.9), which means you need 2 numbers per point, as opposed to the single one you're apparently after, judging your comment.
– Adriaan
Nov 19 '18 at 13:17




Then 1./x would suffice. The plot just creates confusion, since the x locations of corresponding y values also get changed (e.g. the 2nd value of the first plot is at x==1/3, whereas in the second plot it's at x==0.9), which means you need 2 numbers per point, as opposed to the single one you're apparently after, judging your comment.
– Adriaan
Nov 19 '18 at 13:17












@Adriaan if I just get 1./x, this gives me completely different y-axis values from the ones I am looking for (added to the original question).
– Valeria
Nov 19 '18 at 13:25




@Adriaan if I just get 1./x, this gives me completely different y-axis values from the ones I am looking for (added to the original question).
– Valeria
Nov 19 '18 at 13:25












fliplr for row-vectors then? That's not the inverse, but rather 'read in opposite direction'. The images don't help a thing; all they do is confuse me. Can you just show in numbers what you want; i.e. first your x,y pair as you have it now, then what you get using your method, and finally what you want to obtain? Just in numbers?
– Adriaan
Nov 19 '18 at 13:29






fliplr for row-vectors then? That's not the inverse, but rather 'read in opposite direction'. The images don't help a thing; all they do is confuse me. Can you just show in numbers what you want; i.e. first your x,y pair as you have it now, then what you get using your method, and finally what you want to obtain? Just in numbers?
– Adriaan
Nov 19 '18 at 13:29














1 Answer
1






active

oldest

votes


















1














I have managed to find a solution, so for anybody who also need its:



x = linspace(0,1,length(y));
% not needed in this toy example, but can be required for a bigger vector:
[y_unique, idx] = unique(y);
inv_y = interp1(y_unique,x(idx),x);





share|improve this answer

















  • 1




    Note that this is only possible if y is strictly monotoníc. The unique removes duplicate points, making it applicable to any monotonic function.
    – Cris Luengo
    Nov 19 '18 at 14:03


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I have managed to find a solution, so for anybody who also need its:



x = linspace(0,1,length(y));
% not needed in this toy example, but can be required for a bigger vector:
[y_unique, idx] = unique(y);
inv_y = interp1(y_unique,x(idx),x);





share|improve this answer

















  • 1




    Note that this is only possible if y is strictly monotoníc. The unique removes duplicate points, making it applicable to any monotonic function.
    – Cris Luengo
    Nov 19 '18 at 14:03
















1














I have managed to find a solution, so for anybody who also need its:



x = linspace(0,1,length(y));
% not needed in this toy example, but can be required for a bigger vector:
[y_unique, idx] = unique(y);
inv_y = interp1(y_unique,x(idx),x);





share|improve this answer

















  • 1




    Note that this is only possible if y is strictly monotoníc. The unique removes duplicate points, making it applicable to any monotonic function.
    – Cris Luengo
    Nov 19 '18 at 14:03














1












1








1






I have managed to find a solution, so for anybody who also need its:



x = linspace(0,1,length(y));
% not needed in this toy example, but can be required for a bigger vector:
[y_unique, idx] = unique(y);
inv_y = interp1(y_unique,x(idx),x);





share|improve this answer












I have managed to find a solution, so for anybody who also need its:



x = linspace(0,1,length(y));
% not needed in this toy example, but can be required for a bigger vector:
[y_unique, idx] = unique(y);
inv_y = interp1(y_unique,x(idx),x);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 13:45









Valeria

10410




10410








  • 1




    Note that this is only possible if y is strictly monotoníc. The unique removes duplicate points, making it applicable to any monotonic function.
    – Cris Luengo
    Nov 19 '18 at 14:03














  • 1




    Note that this is only possible if y is strictly monotoníc. The unique removes duplicate points, making it applicable to any monotonic function.
    – Cris Luengo
    Nov 19 '18 at 14:03








1




1




Note that this is only possible if y is strictly monotoníc. The unique removes duplicate points, making it applicable to any monotonic function.
– Cris Luengo
Nov 19 '18 at 14:03




Note that this is only possible if y is strictly monotoníc. The unique removes duplicate points, making it applicable to any monotonic function.
– Cris Luengo
Nov 19 '18 at 14:03



Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules