Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately, you are trying to find the values of <code>t</code> associated with a <code>y</code>, and your function is not monotonic so we need to actually code up a mock linear interpolation. Note, there may be a better way, but I do not know of it right now. Try the following code where <code>yVals</code> are the values you want an associated <code>t</code> for, and <code>possArray</code> will include all values of <code>t</code> that may satisfy those conditions. </p> <pre><code>clc; close all; clear all; t = [0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 155 160 165 170 175 180]; y = [0 5 9 19 25 32 46 65 79 90 100 115 123 141 153 159 160 171 181 185 193 200 205 211 215 220 223 222 225 224 228 231 231 228 235 234 231]; plot(t,y) grid on hold on yVals = [18.1,33,70,222.5,230]; possArray = cell(1,numel(yVals)); iter = 1; for val = yVals; poss = []; possNum = 1; for i = 1:numel(y)-1 if y(i) &lt;= val &amp;&amp; y(i+1) &gt;= val minDiff = val-y(i); yDiff = y(i+1)-y(i); percAlong = minDiff/yDiff; poss(possNum) = (t(i+1)-t(i))*percAlong+t(i); possNum = possNum+1; end end possArray{iter} = poss; iter = iter + 1; end colors = hsv(numel(yVals)); legendCell = cell(numel(yVals)+1,1); legendCell{1} = 'Original Line'; for i = 1:numel(yVals) plot(possArray{i},yVals(i)*ones(size(possArray{i})),... 'x','MarkerSize',10,'LineWidth',2,'Color',colors(i,:)) legendCell{i+1} = ['Values for Y = ' ,num2str(yVals(i))]; end legend(legendCell) hold off </code></pre> <p>As stated previously, this is linear interpolation, so if you need it to be more complicated that is on you, the concept should however be similar</p> <p><strong>UPDATE</strong> </p> <p>Updated code above to be a little more clean, and added a plot indicating that multiple possibilities may arise for a single value, and that the code will return all possibilities. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload