exporting listbox to excel while adding spaces in between variable names

3 vues (au cours des 30 derniers jours)
Melissa
Melissa le 19 Août 2014
Commenté : Melissa le 19 Août 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

Réponse acceptée

Aniruddha Katre
Aniruddha Katre le 19 Août 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 = [{''},{''},{''}];
  1 commentaire
Melissa
Melissa le 19 Août 2014
Thank you so much for your detailed explanation it really helped me and your code was spot on!

Connectez-vous pour commenter.

Plus de réponses (1)

Iain
Iain le 19 Août 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

Community Treasure Hunt

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

Start Hunting!

Translated by