필터 지우기
필터 지우기

Extracting 'y' values from plot over an iterating loop

조회 수: 2 (최근 30일)
Kash022
Kash022 2016년 5월 25일
댓글: Adam 2016년 5월 26일
Hello All,
I am trying to extract y values from a plot in matlab. I have used the below code snippet. However, as I have a for-loop iterating (which is needed as I need those values), it keeps giving me an "error using interp1- X must be a vector of numeric coordinates". Any suggestions? Thanks!
figure(107);
for i = 1:25
p1 = loglog(Frequency{i,:},Svg{i,:}); %%%%,'Color',map(i,:)); %%%
LineH = get(gca,'children');
freq=get(LineH,'XData');
psd=get(LineH,'YData');
freq_10 = 10; % the x value for which I need the y value
svg_10{i} = interp1(freq,psd,freq_10);
hold on;
end
  댓글 수: 4
Elias Gule
Elias Gule 2016년 5월 25일
Try using
LineH = findobj(gca,'Type','line'); % All line objects of the current axes
LineH = LineH(i); % Handle for the current line object
Adam
Adam 2016년 5월 25일
If you want to extract things from a line graphics object though by far your best option is to just retain the line handle when you plot it. It is more efficient than having to search the scene for it afterwards.

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

답변 (1개)

Adam
Adam 2016년 5월 25일
Well if freq and psd are 2d matrices then
interp1(freq,psd,freq_10);
is not going to work because interp1 expects vector inputs not a matrix. You should be able to use interp2 on it though, just making sure that in the second dimension your input and output grids are the same so that you don't interpolate in that direction.
Maybe you just meant to use this instead?
svg_10{i} = interp1(freq(i,:),psd(i,:),freq_10);
  댓글 수: 2
Kash022
Kash022 2016년 5월 26일
Hello@Adam: yes, I tried this exactly...but to no use
Adam
Adam 2016년 5월 26일
In what sense? Do you get the same error message? Your inputs to interp1 should at least be vectors in this case.

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

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by