Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

How I can Remove a specific Items from listbox and get its name into a variable??

Asked by Elysi Cochin on 27 Oct 2012

i got the code to delete an item from listbox.... now,,, what if i want to get the name of the deleted item in a variable?? for ex there are 4 images in my listbox... image1.jpg,image2.jpg,image3.jpg and image4.jpg..... i delete image3.jpg... now i want the name image3.jpg in a variable... how to do that... please reply...

0 Comments

Elysi Cochin

Tags

Products

No products are associated with this question.

2 Answers

Answer by Walter Roberson on 27 Oct 2012
Accepted answer

By then it is too late. Keep track of the item before you delete it.

2 Comments

Elysi Cochin on 27 Oct 2012

yes... before deleting i want to save the image name in a variable.. how to do it?? that is ... first i select it from listbox.. then i need to save the image name in variable and then delete... how to do my second step... that is save it ina variable before deleting to show that image is deleted in a msg box... please do reply...

Walter Roberson on 27 Oct 2012
curidx = get(hObject, 'Value');
curstrings = get(hObject, 'String');
variable = curstrings{curidx};
curstrings(curidx) = [];  %delete it in this list
set(hObject, 'String', curstrings);  write new list in

Now the variable named "variable" will hold the string.

msgbox( sprintf('Deleting from list: %s', variable) );
Walter Roberson
Answer by Elysi Cochin on 27 Oct 2012

thank u sir..

sir now what if i want to delete it from the folder itself... that is, 'image.jpg' (we got it in a varible) is stored in a folder 'X'... i want to delete it from the folder X also... is there any way to delete it using the variable name?? please reply sir....

sir this is my path X/image.jpg.... i dont want to delete it this way.... delete('X/image.jpg')..... i want to delete it using the variable name.... please reply.....

2 Comments

Walter Roberson on 27 Oct 2012
filepath = fullfile( 'X', variable );
delete(filepath);
Elysi Cochin on 29 Oct 2012

Thank u so much sir.....

Elysi Cochin

Contact us