How to extract data meet specified condition from a matrix?

Hello everyone, I have a text file which looks like below
DLS: 16-24-48-26W4 747.88 746 Sandstone
DLS: 16-24-48-26W4 746 744.88 Sandstone
DLS: 16-24-48-26W4 744.88 744.19 Sandstone
DLS: 16-24-48-26W4 744.19 741.63 Siltstone
DLS: 16-24-48-26W4 741.63 741.33 Mudstone
DLS: 16-24-48-26W4 741.33 740.96 Sandstone
DLS: 16-24-48-26W4 740.96 740.77 Mudstone
DLS: 16-24-48-26W4 740.77 739.74 Coal
DLS: 16-24-48-26W4 739.74 739.64 Mudstone and siltstone
DLS: 16-24-48-26W4 739.64 738.92 Sandstone
DLS: 16-24-48-26W4 738.92 738.74 Siltstone
DLS: 16-24-48-26W4 738.74 738.64 Coal
DLS: 16-24-48-26W4 738.64 738.55 Mudstone
DLS: 16-24-48-26W4 738.55 738.37 Coal
DLS: 16-24-48-26W4 738.37 737.87 Siltstone
DLS: 16-24-48-26W4 737.87 737.45 Siltstone
DLS: 16-24-48-26W4 737.45 737.23 Mudstone
DLS: 16-24-48-26W4 737.23 737.13 Siltstone
DLS: 16-24-48-26W4 737.13 737.08 Mudstone
DLS: 16-24-48-26W4 737.08 736.62 Coal
DLS: 16-24-48-26W4 736.62 735.89 Sandstone
DLS: 16-24-48-26W4 735.89 735.09 Sandstone
DLS: 16-24-48-26W4 735.09 734.48 Sandstone
DLS: 16-24-48-26W4 734.48 733.62 Sandstone
I wanna extract depth information for different types of rocks such as sandstone, claystone,coal etc. The depths are the third and fourth columns.I think there should be some ways to write a loop to extract these data, but I dont know how to do it. Please let me know if anyboday know how to do it or advice. Thanks.

4 Comments

Are there line breaks in this text file? I don't see any columns. What defines a column? Have you looked at textscan?
Hi Daniel,
Sorry, I have trouble to attach these data correctly.
Here is one row of the data:
DLS: 16-24-48-26W4 747.88 746 Sandstone
From column 1 to column 5 of row 1.
and second row looks like this:
DLS: 16-24-48-26W4 746 744.88 Sandstone
I am not importing these data into matlab.Instead,I want extract information of specific types of rock. For example, this row is the data of sandstone.My data have thoundsands of rows...I want estalish a database for different types of rocks.Obviously, I cant manually pick, so i am wondering if anyboday know how to do this.
Thanks.
Hi,
Import the text file into Matlab. Try to convert it into cell array. once you have the data in cell format you can extract the row data by comapring teh strings using strcmp. If you have trouble importing the file into matlab probably it needs some preprocessing. Hope this helps.
Hi Krishna,
I have no problem to import this data.I can use textscan. If I use textscan, the results would be in a cell.The thing is that I dont know how to use string variables.I will take a look at the strcmp one. Thanks for your help!

Sign in to comment.

Answers (1)

You say "I am not importing these data into matlab." Have you considered Excel? It will be able to handle this, plus do sorting by rock type, various kinds of plotting, or whatever.

4 Comments

Hi, thanks for your response.
I am going to use matlab precess these data, thats why I poseted my questions here.
What i mean is that I know how to import this data into matlab,but i dont know how to extract depths information of different types of rocks. I have another dataset which corresponse to this lithology with exactly the same depth, but the depth increment is 0.02 meters. So i think I should come up with some matlab code to deal with this problem
Well . . . you never answered Daniel's question about whether you tried to use textscan. I'm wondering the same thing.
Hi
I used textscan to import my dataset into matlab
fid=fopen('ECC_LAS_10_Lithlogs.txt');
A=textscan(fid,'%s%s%s%s%s');
And now i am trying to use cellfun plus strcmp funtions to extract specific lithology depth information.
However,I found that after I use textscan,the cell A. For example,A{:,5} which is the lithology cell,does not have single quotation marks.
Because i am trying to use this code:
a = {'OL',4;'WR',7;'OL',3;'AT',2}
c=arrayfun(@(x) strcmp(x,'OL'),{a{:,1}});
I dont know why
B=arrayfun(@(x) strcmp(x,'sanstone'),{A{:,5}});
the returned result is zero. I guess the reason is that after I use textscan. My A{:,5} is not string cauz i looked at these data. they dont have quotaion marks

Sign in to comment.

Categories

Asked:

Lei
on 26 Apr 2012

Community Treasure Hunt

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

Start Hunting!