Store and Retrieve simple text box content using GUI
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ahmed obaid
el 15 de Mzo. de 2016
Comentada: Adam
el 16 de Mzo. de 2016
Dear users
I have a question about store and retrieve IDs and names by using matlab , following my simple GUI and there are only two (text box 1 , text box 2) when i entered some authors names along with its ids ,
then for search purpose I need to enter only the ID then when i press search will retrieve the name correspond to that id , is there any way to do that i will thank any one can help me in this manner ..
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157865/image.jpeg)
0 comentarios
Respuesta aceptada
Adam
el 15 de Mzo. de 2016
Editada: Adam
el 15 de Mzo. de 2016
doc containers.map
should help with this if your IDs are not guaranteed to be contiguous and starting from 1. There are examples in the help and using numeric indices is very easy anyway. It has the advantage over an array that your indices can be any numeric (or string) value.
If you are struggling with the underlying GUI aspect of it then that is a different matter, but a containers.Map object should work well to store all your data, assuming IDs are unique which seems a safe assumption given you are searching based on them.
4 comentarios
Adam
el 16 de Mzo. de 2016
In your openingFcn you should declare the map - e.g.
handles.mappings = containers.Map;
Then in your 'Add' callback you simply do something like:
id = str2double( get( handles.editId, 'String' ) );
name = get( handles.textName, 'String' );
handles.mappings( id ) = name;
guidata( hObject, handles );
In your search callback something like:
id = str2double( get( handles.editId, 'String' ) );
name = handles.mappings( id );
set( handles.textName, 'String', name );
That is a rough and ready untested example of the type of code that is needed. To be robust you need to do a check using isKey( ) on the map before trying to retrieve the name from the mappings because if the key does not exist within the map you will get an error. If you test for the key then you can use
doc errordlg
for example to present a relevant message to the user.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!