Filter löschen
Filter löschen

How to read a specific line containing a value?

7 Ansichten (letzte 30 Tage)
jacques baptiste
jacques baptiste am 20 Mär. 2018
Kommentiert: jacques baptiste am 22 Mär. 2018
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 Kommentare
Guillaume
Guillaume am 20 Mär. 2018
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.
jacques baptiste
jacques baptiste am 20 Mär. 2018
No reason, I used it because I knew this function. is there any advantage to use readtable? Yeah it was not a good example sorry, my excel file is a file to test with random value/name (see attachment).
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).
Then i want to display name and ID in 2 edit text boxes in a GUI made with GUIDE. Sorry if it is not clear.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Guillaume
Guillaume am 20 Mär. 2018
"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.
  1 Kommentar
jacques baptiste
jacques baptiste am 22 Mär. 2018
Thanks a lot for the explanations, it's working perfectly with readtable and the structure format.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by