How to read a specific line containing a value?
조회 수: 8 (최근 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에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!