MATLAB Answers

plotting on curve given only x value in a loop

1 view (last 30 days)
Benjamin
Benjamin on 18 Mar 2019
Answered: Star Strider on 18 Mar 2019
I have the following code:
for i=1:1:10
plot(data{1, i}(:,2),data{1, i}(:,4));
C = data{1, i}(:,4)./data{1, i}(:,2);
vint = pi*sqrt(2)/3 * cumtrapz(data{1, i}(:,2), data{1, i}(:,4)./data{1, i}(:,2));
X_M(i) = interp1(vint, data{1, i}(:,2), 1);
X_M_temp = interp1(vint, data{1, i}(:,2), 1);
xlim([1 2]);
grid on;
hold on;
plot(X_M_temp,'o')
end
It basically computes an integral and X_M_temp is where the integral is equal to 1. You can see this is in a loop 10 times. If I have this X_M_temp, which is an x value of the plot, is there a way I can plot a symbol for each line (each time through the loop) where X_M_temp is the x-value, and the y-value should be wherever that falls on the current line on the plot? Note that X_M(i) stores the whole array, but I was having less luck using this, so I created X_M_temp which just holds the current value. However, I can't seem to get them to plot X_M_temp (the x-value) with whatever y-value that would correspond to on the line.
Note that
data{1, i}(:,2)
corresponds to the X-values. Could I interpolate X_M on here, and find the interpolated y-value (which would be in the
data{1, i}(:,4)
column)? X_M won't fall on an exact point in the x-data, so maybe I should interpolate the y-values? Maybe this way is overkill? Is there a way I can plot X_M for each line, such that the y-value is just where X_M crosses the line?

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by