# Inverse of 1D vector Matlab [closed]

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)`: Now, however, I want an inverse graph, so I make a plot with `plot(y,x)`: 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`: • 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
• 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

``````x = linspace(0,1,length(y));
• 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.93051255,"math_prob":0.9028827,"size":1677,"snap":"2021-31-2021-39","text_gpt3_token_len":511,"char_repetition_ratio":0.103407055,"word_repetition_ratio":0.01910828,"special_character_ratio":0.31842577,"punctuation_ratio":0.17814727,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9977614,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,1,null,1,null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-31T20:04:37Z\",\"WARC-Record-ID\":\"<urn:uuid:57daf459-0070-4b49-aefa-016b33add4f5>\",\"Content-Length\":\"157607\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7bd87769-97ca-4206-a2e0-5f730401a86c>\",\"WARC-Concurrent-To\":\"<urn:uuid:95699bb3-c063-467b-81f8-1850a8f9297c>\",\"WARC-IP-Address\":\"151.101.129.69\",\"WARC-Target-URI\":\"https://stackoverflow.com/questions/53375194/inverse-of-1d-vector-matlab\",\"WARC-Payload-Digest\":\"sha1:VJKUXUTQMALPTIDC45TTSKODSGYWKSV4\",\"WARC-Block-Digest\":\"sha1:GMFWRLUKY6GCWKTGXHESVZK6BMDLYABI\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046154099.21_warc_CC-MAIN-20210731172305-20210731202305-00260.warc.gz\"}"}