Finding text - Can't locate where specific text is...
4 ビュー (過去 30 日間)
古いコメントを表示
I'm importing an excel file with cells that have values, and cells that are text.
Example
A | B | C
Noise | dB | 48
COx | V | 1.329
I import it as...
[data txt] = importxls('xxx.xls');
So data has my values and txt has the text cells. Note, text includes single quotation marks, so... 'Noise' 'COx'
Text repeats itself throughout the text matrix(?), and I would like to locate where in the array each unique text occurs, so that I can locate the corresponding value, because the order of the values is not always the same.
Help? Thanks.
PS - I feel like I ask very basic questions, and it may be a hassle for people to answer these types of questions. And I feel as though I spend a lot of time looking through the website, and other sites, for help.Does Mathworks have another way find solutions to simple problems? An easier way to find answers..?
0 件のコメント
回答 (3 件)
Matt Tearle
2011 年 5 月 23 日
I don't know what you're planning to do with this data, but it seems like some of the data types available in Statistics Toolbox might be useful. In particular, you could convert text(:,1) to a nominal. Then you can do logical indexing, just like you would with numbers:
A = nominal(text(:,1));
idx = (A == 'Noise');
mean(values(idx))
Even better, you can do grouped operations using grpstats.
Aside 1: when you say importxls do you mean xlsread?
Aside 2: to answer your PS questions, you could always take one of our excellent training courses... :) [Disclaimer: I'm an not an objective observer!] MATLAB Fundamentals, MATLAB for Data Processing and Visualization, and Statistical Methods in MATLAB are some possibilities that might be useful to you.
EDIT TO ADD Without Stats TB, you could do
A = text(:,1);
idx = strcmp('Noise',A);
mean(values(idx))
2 件のコメント
Matt Tearle
2011 年 5 月 23 日
Stats TB is not on all licenses, but it is very common. Try
which nominal
and see what the result is. Either way, I edited my answer to avoid using nominals.
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!