Return value from a UITABLE

2 visualizaciones (últimos 30 días)
mtr
mtr el 14 de Feb. de 2013
Hi All,
Does anyone know if there is a way to search for a specific value in a UI Table and return the value in the column next to it?
I am using a GUI and the user selects a value from a lsitbox and I would like to look for that selected value in the 3 column UITABLE that is in the GUI (that already has data in it) and return the value in the column next to it.
They value being searched for is always in column 1 of the UITABLE (if that helps at all).
Any help is appreciated!!
Rob

Respuesta aceptada

Walter Roberson
Walter Roberson el 14 de Feb. de 2013
Editada: Walter Roberson el 14 de Feb. de 2013
curdata = get(handles.uitable, 'data');
tf = ismember(curdata(:,1), ValueToLocate);
adjacent_value = curdata(tf, 2);
if numel(adjacent_value) ~= 1
error('match fail');
end
This would probably leave you with a 1 x 1 cell, so use adjacent_value{1}
  5 comentarios
Walter Roberson
Walter Roberson el 15 de Feb. de 2013
Are the uitable entries in a different order? If not, then the entry you want is
curdata{rownumber, 2}
mtr
mtr el 18 de Feb. de 2013
No they are in the same order. Walter, I was actually able to get this working using a response from you on another thread (go figure! http://www.mathworks.com/matlabcentral/answers/24300):
strings = get(hObject, 'string');
curval = get(hObject, 'value');
if iscell(strings)
curstring = strings{curval};
else
curstring = strings(curval, :); %char array
end
Thanks for all the help!
R

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 14 de Feb. de 2013
Get the table data:
tableData = get(handles.table1, 'Data');
You might have to use cell2mat(tableData) - I don't remember. Then use extract the column you're looking for and use ismember() or find() to find the matching value. Be sure to know the FAQ. So you might want to do
theColumn = tableData(:, 1); % Get column 1
row = find(abs(theColumn - theSoughtValue) < 0.00001);
Then just get the next column.
theValueWeWant = table(row, 2);
  1 comentario
mtr
mtr el 18 de Feb. de 2013
Thanks Image Analyst, I was able to get it working using walters code above but appreciate the suggestion.
R

Iniciar sesión para comentar.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by