Finding x-values from found y-values

I have the previously pictured plot, and i have found the half intensity values using ginput. I now want to know how i can find the corresponding x values.
This is the code i have thus far: %% Experiment 6
load('Experiment_6.mat');
step_1 = (1:10000)/400;
step_2 = (1:20000)/400;
%%Data Analysis
% Data 1
plot(step_1,data_1); hold on;
y_1 = ginput(2);
y_1 = (y_1(:,2)).*.5
where step_1 corresponding to the x values and i want to find the x values that corresponding to the y values in the array y_1.
Any help will be much appreciated.
Thanks Michael

답변 (3개)

Justin
Justin 2014년 5월 2일

0 개 추천

If I understand the question correctly you want may just be able to use ginput and ask it to return both the X and Y coordinates:
[X, Y] = ginput(2)

댓글 수: 4

Michael
Michael 2014년 5월 2일
Unfortunately, that is not exactly what i needed. In a sense i am trying to find the full width at half max, however since the peaks are asymmetric i am first finding the max values for the leftmost/rightmost intensities (y-values) and then halving them. I then want to find the corresponding x-value that goes along with the newly acquired y-values.
Justin
Justin 2014년 5월 2일
편집: Justin 2014년 5월 2일
Just to make sure I understand lets say you have an x and y you are plotting:
x = -5:5;y = x.^2;
plot(x, y)
So there is a yValue that is arbitrary and may not exist in the known y values:
yVal = 4.7;
hold on; plot(x, repmat(yVal, [length(x) 1]));
So you want to find the x that corresponds to the intersection of those lines?
One way would be to find minimums of where the yValue gets close to the plotted Y's. Something like the file exchange function extrema might make it easier.
plot(x, abs(y-yVal))
And then using extrema
[~, ~, mins, minDex] = extrema(abs(y-yVal));
So minDex would be the index values of your x and y for where the y value was closest to your plotted values. Here the y would be the same as your data_1.
x(minDex)
ans =
-2 2
Michael
Michael 2014년 5월 2일
this worked... wow i really appreciate it
Justin
Justin 2014년 5월 2일
No problem, don't forget to choose best answer :)

댓글을 달려면 로그인하십시오.

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 2일
편집: Azzi Abdelmalek 2014년 5월 2일

0 개 추천

ymax=findpeaks(data_1)
ii1=find(data_1>ymax(1)/2,1)
ii2=numel(data_1)-find(fliplr(data_1)>ymax(2)/2,1)+1
step_width=step_1(ii2)-step_1(ii1)
Image Analyst
Image Analyst 2014년 5월 2일

0 개 추천

I don't see any reason to use ginput at all unless you want the user to guess at the locations. You can use max() and find():
maxY = max(y);
halfMaxLeftIndex = find(y>=maxY/2, 1, 'first'); % x1
halfMaxRightIndex = find(y>=maxY/2, 1, 'last'); % x2
It finds the max value and then finds the first and last index in the array where y is greater than half the max value.

카테고리

도움말 센터File Exchange에서 Data Exploration에 대해 자세히 알아보기

질문:

2014년 5월 2일

답변:

2014년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by