exporting listbox to excel while adding spaces in between variable names
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Melissa
el 19 de Ag. de 2014
Comentada: Melissa
el 19 de Ag. de 2014
Good Morning All,
I have created a GUI which uses a listbox of some parameter names. I am looking to export the parameters chosen as column heads of an excel spreadsheet, however I want to know how to add a blank column in between each selected parameter.
I know how to obtain the Names and Index of the listbox by:
Variable_Name = get(handles.Parameter_Listbox,'String');
Index = get(handles.Parameter_Listbox,'Value');
Now to create a space between the names I thought I could use a loop to build a matrix and tried the following:
for i=1:length(Index)
OutputTitles(i)=[Variable_Name(Index), ' '];
end
Then I could just use xlswrite(Output_File,OutputTitles,Sheet1,Range1);
I was also wondering if anyone could tell me how to skip more than one column header too. Say I wanted to put the Parameter Name every 5th column instead.
Thanks so much,
Mel
0 comentarios
Respuesta aceptada
Aniruddha Katre
el 19 de Ag. de 2014
Your idea of using a loop to insert spaces should work. Note that "Variable_Name" will contain a cell array. So to insert a blank column between the variable names, you can execute a loop that looks like this:
spacing = {''};
OutputTitles = [];
for ii = 1:length(Index)
if isempty(OutputTitles)
OutputTitles = [OutputTitles Variable_Name(Index(ii))];
else
OutputTitles = [OutputTitles spacing Variable_Name(Index(ii))];
end
end
Then you can just call "xlswrite". If you want to put more empty columns between variable names, you can just add the number of empty cells in "spacing" as follows:
spacing = [{''},{''},{''}];
Más respuestas (1)
Iain
el 19 de Ag. de 2014
Its playing with cell arrays:
Variable_Name = {'One','Two','Many'};
chosen_variable_names = Variable_Name(index);
Output_Table{1,1} = chosen_variable_names{1}; % column 1
Output_Table{1,3} = chosen_variable_names{2}; % column 3
Output_Table{1,45} = chosen_variable_names{3}; % column 45
0 comentarios
Ver también
Categorías
Más información sobre Spreadsheets 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!