update the column headng by readin the excel file
    5 views (last 30 days)
  
       Show older comments
    
How to update the column heading of a cell vector which holds the combination?
0 Comments
Accepted Answer
  Star Strider
      
      
 on 14 Jul 2023
        
      Edited: Star Strider
      
      
 on 14 Jul 2023
  
      If you want the variable names, first: 
T1 = readtable('YourFile.xlsx', 'VariableNamingRule','preserve')
then: 
ColumnHeadings = T1.Properties.VariableNames;
then for example: 
FirstHeading = ColumnHeadings{1};
to return the first heading (variable name).  
EDIT — (14 Jul 2023 at 15:27)
% figure
% imshow(imread('2023-07-14_13h06_04.png'))
data = readtable('Book2.xlsx', 'VariableNamingRule','preserve')
emptyRows = all(ismissing(data),2);
data(emptyRows,:) = [];
variable = data.Parameters; 
values = {};
for i = 1:size(data, 1)
    values{i} = table2array(data(i, 5:end)); 
    values{i}(all(ismissing(values{i}),2),:) = [];
end 
% remove empty cell
values = values(~cellfun(@isempty,values));
combinations = combvec(values{:})';
combinations = sortrows(combinations,1);                        % <— ADDED
Lv = ~all(ismissing([data.Value1 data.Value2]),2);              % <— ADDED
p = variable(Lv);
comitable= array2table(combinations);
comitable.Properties.VariableNames = p(1:size(combinations,2))
EDIT — (14 Jul 2023 at 15:57)
Added ‘Lv’ (and references to it) to select the correct values of ‘p’.  
17 Comments
  Star Strider
      
      
 on 27 Jul 2023
				Mixed numeric and text can only be combined in a cell array or a table, and a string array is another option (although I am not certain that it is much of an improvement over the cell array here, other than with respect to indexing).  The cell2table function might be an option.  
Perhaps one of these — 
C = {{'50'}    {'15'}    {'Name'}
    {'75'}    {'15'}    {'Name'}
    {'50'}    {'10'}    {'Age' }
    {'75'}    {'10'}    {'Age' }
    {'50'}    {'15'}    {'Age' }
    {'75'}    {'15'}    {'Age' }
    {'50'}    {'10'}    {'Name'}
    {'75'}    {'10'}    {'Name'}};
T1 = cell2table(C)
Text = string(C(:,3));
T2 = array2table(cellfun(@str2double,C(:,[1 2])), 'VariableNames',{'N1','N2'});
T2 = addvars(T2, Text)
S = [cellfun(@str2double,C(:,[1 2])) string(C(:,3))]
.
More Answers (1)
  Image Analyst
      
      
 on 14 Jul 2023
        You forgot to attach your workbook, and forgot to say what kind of variable you want to work with in MATLAB (table, cell array, double).  Cell arrays don't have column headings unless you mean the first row of the cell array.  If you have the first row be a string, and subsequent rows have numbers, then you'd be best off using a table instead of a cell array.
t = readtable(yourWorkbookFileName)
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
0 Comments
See Also
Categories
				Find more on Text Data Preparation in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!