Finding row number of a variable existing in a table
70 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Isti Pallai
am 20 Nov. 2020
Beantwortet: Isti Pallai
am 20 Nov. 2020
Hi,
I've been searching the internet for a while trying to find the combo of functions that will allow me to find the row number of an inputted variable.
More specifically, I began with importing an excel (.xlsx) file as a table via the readtable() function.
Then I prompted the user to deliver a string stored as a variable (searching in the MeasName column) and another prompt to be stored as a number (as a filter for ID# column).
I would like to find a way to run through the table and be able to return the correct row and column of a variable.
Ex:
ID# MeasName# Coeff1 Coeff2 Coeff3 (headers)
Table[
1 A 12 13 14
1 B 14 13 12
2 A 1 2 3
2 B 3 2 1]
So I run my code and get this in the command window:
Which ID#?: 2 [Enter]
Which MeasName?: A [Enter]
I would like the code to be able to locate return a vector of [m,n] and in this case it would be [3,2].
then define a variable RowNumber = 3 and ColumnNumber = 2
Thanks for helping me out.
0 Kommentare
Akzeptierte Antwort
Peter Perkins
am 20 Nov. 2020
I have no idea what you mean by "In this case the second column and third row of the table.", but this sounds like what you want:
i = find(T.ID# = userID & t.MeasName# == userMeasName)
and maybe even
T(i,:)
I can't tell if the #'s are really part of the table's var names, or what. I can't tell if MeasName# is string, cellstr, or char. So you get to adjust this to whatever you actually have (which might mean using strcmp instead of ==). Please try to be precise.
1 Kommentar
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!