MATLAB Answers

0

Import a .txt into a cell of a table?

Asked by Tobias Wzl on 12 Oct 2017
Latest activity Commented on by Tobias Wzl on 17 Oct 2017
Hello everybody,
it might seems easy to some of you but I'm struggling to import a .txt or a .csv - file into a single cell of a table in Matlab.
I've read all the sites like load variables or import data and other stuff.
for a better understanding i attached a picture of my created table.
The task i want to realize is that if click on a cell (each cell of the column should be able to do this) in the column of 'transient', I want a window to pop up, so I can select a .txt-file (contains a number for Power and a number for the time)
Is this even possible?
I'm hoping for some help :)
if you need my code for the table as well, tell me

  0 Comments

Sign in to comment.

1 Answer

Answer by Aveek Podder on 17 Oct 2017

Hi,
You can use CellSelectionCallback and uigetfile to load data from a file.

  2 Comments

Thank you for your answer !
I'm already trying something
do you think this code would help me
my actual main code:
% --- 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);
Data{i} = '';
for i = 1:numel(Data)
end
handles.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
and after this then the cellselectioncallback ?
would consider something like this:
function data_uitable1_CellSelectionCallback(hObject, eventdata, handles)
% hObject handle to data_uitable (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
% Indices: row and column indices of the cell(s) currently selecteds
% handles structure with handles and user data (see GUIDATA)
% disp(eventdata)
handles.datatable_row = eventdata.Indices(1);
handles.datatable_col = eventdata.Indices(2);
guidata(hObject, handles);
This is something I found on the internet is this appropriate for me or not? What do I have to change?
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
This is some other code I tried... but I don't have a clue how to import my file into a cell of my column now -.-
I'm pretty frustrated with this right now .....

Sign in to comment.