Import txt/csv into a cell of a column
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello everyone,
this is my code I'm struggling with:
% --- FIGURE -------------------------------------
handles.figure1 = figure( ...
'Tag', 'figure1', ...
'Units', 'characters', ...
'Position', [102.8 24.2307692307692 126.8 33], ...
'Name', 'Parameter', ...
'MenuBar', 'figure', ...
'NumberTitle', 'off', ...
'Color', [0.941 0.941 0.941]);
% --- UITABLE -------------------------------------
% Initialize empty string for components of the Data
Data=cell(16,5);
for i = 1:numel(Data)
Data{i} = '';
end
uitable1 = uitable( ...
'Parent', handles.figure1, ...
'Tag', 'uitable1', ...
'UserData', zeros(1,0), ...
'Units', 'characters', ...
'Position', [12.2 8 85.6 21], ...
'BackgroundColor', [1 1 1;0.961 0.961 0.961], ...
'ColumnEditable', [true,true,true,true,true], ...
'ColumnFormat', {'char','char','char','char','char'}, ...
'ColumnName',{'ID','<html>P<sub>i</sub> -stationary<br>[W]','<html>P<sub>i</sub> -transient<br>[W/t]','<html>&Omega','V'}, ... % '<html>P<sub>i</sup></html>[W]'für griechische Buchstaben in einer Column <HTML>&Buchstabe
'ColumnWidth', {'auto','auto','auto','auto','auto'}, ...
'Data',Data); % add the "string" Data
function uitable1_CellEditCallback(hObject, eventdata, handles)
Columndata = get(hObject,'Data');
[FileName,PathName] = uigetfile({'*.txt'; '*.csv'},'Select the configuration');
if strcmp(Columndata(1,1),'User Defined')
FilePath = fullfile(PathName,FileName);
if isequal(FileName,0)
return
end
[pathstr, name, ext] = fileparts(FilePath);
ParameterList{end+1} = name;
set(uitable1,'ColumnFormat',{ParameterList});
end
end
which command(s) do I need so I can import my txt or csv File into a cell of a column (should work for all the cells of the column P_i-transient)
tried it with importdata or fopen and it didnt work for me, I think I used it wrong :( can somebody help me with the right command(s) and where to put them?
댓글 수: 2
채택된 답변
Arvind Narayanan
2017년 10월 23일
Hi Tobias,
Although there is no direct way to assign different callbacks for cells from different columns, you may use the eventdata structure from the CellEditCallback and the CellSelectionCallback to find the row and column indices of the cell being selected. Following this, you can define some conditional loop statements so that the behavior of the callback differs depending upon the row or column index( as per your requirement).
To control the color of the text that appears in the cell, change the Foreground Color property from within the above-mentioned callback itself.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!