I am very new to Matlab and have only ever used maple. I am trying to use string compare on huge imported data (26,000 rows) to a specific word to find the row that contains it.
I understand the basics of strcmp and can use it within matlab, but cannot figure out how to use it for a data set. So for example, I am currently working with the code:
s1 = 'RT'; s2 = {ImpD(:,4)}; TF = strcmp(s1, s2); find(TF);
ImpD(:,4) since I am looking for the specific text in the 4th column. I just don't think Matlab is realizing I am referencing the imported data. How can i fix this?

6 件のコメント

Guillaume
Guillaume 2018 年 2 月 11 日
what is
class(ImpD)
and if it cell, what is
class(ImpD{1, 4})
Jacob Barrett-Newton
Jacob Barrett-Newton 2018 年 2 月 11 日
Its returning it as a table. So that class(ImpD{1,4}) is a string
Jacob Barrett-Newton
Jacob Barrett-Newton 2018 年 2 月 11 日
Ah, I think your comment has just helped me to fix things. I had it imported as a table, i imported it as a string array and it seems to have returned what i want. Like i said I am very new to this. Thanks for helping me to realise
Jacob Barrett-Newton
Jacob Barrett-Newton 2018 年 2 月 11 日
Is there a way to make this into a loop? As I have about 20 words i need to find in this massive data set, which i could do individually but it would be nice to be able to write a loop that will do it all at once
Guillaume
Guillaume 2018 年 2 月 11 日
Is it string or char array? People use the two interchangeably but they are actually two very different types. comparisons are easier with strings.
Since ImpD is a table, what is the name of the fourth column?
Jacob Barrett-Newton
Jacob Barrett-Newton 2018 年 2 月 11 日
Well now that i have imported it as a string array, class(ImpD) returns string and class(ImpD{1, 4}) returns char

サインインしてコメントする。

 採用された回答

Guillaume
Guillaume 2018 年 2 月 11 日

1 投票

If ImpD is a string array with a least four columns:
ismatch = ImpD(:, 4) == "RT"
to find "RT" in the fourth column.
If it were a table as you had initially:
ismatch = ImpD{:, 4} == "RT"
%or
ismatch = ImpD.column4name == "RT" %replace column4name by actual name
If you're going to wrap the above in a loop to find different strings and do something then it is very likely that there is a much better way. A better explanation of what you want to achieve and of the starting point would be required.

1 件のコメント

Jacob Barrett-Newton
Jacob Barrett-Newton 2018 年 2 月 11 日
well after I identify which rows contain which bit of text, I can then extract the values from the corresponding columns and plot it. The required text is also imported. Its a table with the text i need in the second column. At the moment now that I can find the row I can just one by one search for it, but like I said being able to loop it would make it a lot cleaner and easier.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Characters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by