How do I find my wanted values in a .txt-file?

I succeeded to let Matlab read a .txt-file with two columns (let's say t and w) but now I want it to give me w(t), so for a certain value in the first column I want to know what the associated value is in the second column. Any ideas? I have been playing with ind=find(..) but couldn't make that work yet.

 채택된 답변

Jacques
Jacques 2014년 3월 13일

0 개 추천

댓글 수: 3

Evelyn
Evelyn 2014년 3월 13일
편집: Evelyn 2014년 3월 13일
Don't get it to work, but wouldn't the problem stay the same? If I have the table, how do I know what value in the second column belongs to the value I know to have in the first column?
Matt Kindig
Matt Kindig 2014년 3월 13일
편집: Matt Kindig 2014년 3월 13일
I think ismember() might do the trick.
%create some sample data.
w= rand(10,1); [~, t] = sort(w);
%t values you want to match
tvals = [5; 3; 2];
[~, loc] = ismember(tvals, t); %where are tvals in t?
wvals = w(loc); %corresponding w values
if you have the txt file imported in (let's call it DATA which has size n by 2 where first column is t and the second column is the value for w associated with the t in the same row)then ind = find should work out fine. example:
DATA = [1:10]';
DATA = [DATA DATA.^2];
tindex = find(DATA(:,1) == 4); %find row with the desired value in first column
w = DATA(tindex,2) %get value to the right of the value you found for t.

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

추가 답변 (0개)

카테고리

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

질문:

2014년 3월 13일

댓글:

2014년 3월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by