exporting listbox to excel while adding spaces in between variable names

2 ビュー (過去 30 日間)
Melissa
Melissa 2014 年 8 月 19 日
コメント済み: Melissa 2014 年 8 月 19 日
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

採用された回答

Aniruddha Katre
Aniruddha Katre 2014 年 8 月 19 日
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 件のコメント
Melissa
Melissa 2014 年 8 月 19 日
Thank you so much for your detailed explanation it really helped me and your code was spot on!

サインインしてコメントする。

その他の回答 (1 件)

Iain
Iain 2014 年 8 月 19 日
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

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by