Clear Filters
Clear Filters

Finding x-values from found y-values

3 views (last 30 days)
Michael
Michael on 2 May 2014
Answered: Image Analyst on 2 May 2014
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

Answers (3)

Justin
Justin on 2 May 2014
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 Comments
Michael
Michael on 2 May 2014
this worked... wow i really appreciate it
Justin
Justin on 2 May 2014
No problem, don't forget to choose best answer :)

Sign in to comment.


Azzi Abdelmalek
Azzi Abdelmalek on 2 May 2014
Edited: Azzi Abdelmalek on 2 May 2014
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 on 2 May 2014
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.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!