How to read a specific line containing a value?
7 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I would like to read the excel line where for example the ID "445678" is written, in order to display the data into edit text box (only 2 columns actually). I did try with find but my excel is composed by numbers and letter so this is not working.
A little help would be appreciated, even just a way of doing it. Thanks for reading
Best regards, Baptiste
4 件のコメント
Guillaume
2018 年 3 月 20 日
Any reason you're not using readtable instead of xlsread? It would make your life easier.
I don't understand how the screenshot relates to your code where you appear to be searching for the values 101 to 109 which do not appear in that screenshot. In any case, a loop is not required. ismember with the 'rows' option is probably what you need.
I also don't understand how your code relates to your question of finding ID 445678.
Finally, rather than a screenshot (wich we can't use to test code), a demo excel file would be more useful.
採用された回答
Guillaume
2018 年 3 月 20 日
"is there any advantage to use readtable?"
It's simply a more powerful version of xlsread. It figures out the format of the excel file (also works with text file), use that to label the columns and outputs a table. Tables are easier to work with than cell arrays.
If it weren't for that single 'k' on row 15, all you had to do to read the file was:
t = readtable('PVdata.xlsx')
With that 'k', it needs a hint:
t = readtable('PCdata.xlsx', 'Range', '1:10')
"I want to be able to get the project name (column 1) and the ModuleID (column 3) from the channel number (101,102.. column 4)"
I'm not entirely clear what you want. To get the project name and module ID for e.g. channel 103:
t.ProjectName(t.Channel == 103)
t.ModuleId(t.channel == 103)
See how easy it is to work with tables.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!