How to select more than 1 selection using Listdlg and export the output to excel?

2 visualizaciones (últimos 30 días)
Hello Guys,
This is my code to select an option
Weight_lbs={'1234','4561','4556','4545','3345'};
[indx1,tf1] = listdlg('PromptString',{'Select weight'},'SelectionMode','multiple','ListString',Weight_lbs);
s1=evalin('base','indx1');
if s1 == 1
Weight_lbs = 1234;
elseif s1 == 2
Weight_lbs = 4561;
elseif s1 == 3
Weight_lbs = 4556;
elseif s1 == 4
Weight_lbs = 4545;
elseif s1 == 5
Weight_lbs = 3345;
else
Weight_lbs = 3345;
end
Trailer={'pen','pencil','scale','eraser'};
[indx2,tf2] = listdlg('PromptString',{'Select weight'},'SelectionMode','multiple','ListString',Trailer);
s2=evalin('base','indx2');
if s2 == 1
Trailer = "pen";
elseif s2 == 2
Trailer ="pencil";
elseif s2 == 3
Trailer = "pencil";
elseif s2 == 4
Trailer = "scale";
else
Trailer = "pen";
end
I need to export the selected options to excelsheet.
I could able to export single selection but when I select more than 1 it is exporting the first selected ones. I know I cannot export both options because indx2 can take only one value.
For example, If I select 1234 and 4556 under weight and pen and pencil under Trailer. I should see 1234,4556 and pen,pencil in excel.
How to export both selected options ? Any ideas or suggestions greatly appreciated.
Thank you in advance

Respuestas (1)

Benjamin Thompson
Benjamin Thompson el 15 de Feb. de 2022
Your code can be simplified quite a bit. Then use xlswrite to write out to Excel:
Weight_lbs={'1234','4561','4556','4545','3345'};
[indx1,tf1] = listdlg('PromptString',{'Select weight'},'SelectionMode','multiple','ListString',Weight_lbs);
Weight_lbs_selected = Weight_lbs(indx1);
xlswrite('sampleExcelFile', Weight_lbs_selected);
Trailer={'pen','pencil','scale','eraser'};
[indx2,tf2] = listdlg('PromptString',{'Select weight'},'SelectionMode','multiple','ListString',Trailer);
s2=evalin('base','indx2');
Trailor_selected = Trailer(indx2);

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by