update the column headng by readin the excel file
조회 수: 1 (최근 30일)
이전 댓글 표시
How to update the column heading of a cell vector which holds the combination?
댓글 수: 0
채택된 답변
Star Strider
2023년 7월 14일
편집: Star Strider
2023년 7월 14일
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
Star Strider
2023년 7월 27일
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))]
.
추가 답변 (1개)
Image Analyst
2023년 7월 14일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!