GUI How to insert multiple csv into uitable?

2 次查看(过去 30 天)
Hello, I am new in Matlab and I am using Matlab 2019a version. I have window build in guide in Matlab, you can se how the window looks like in png file whitch I insert there. I tried many combination, some of it works but it is still not that I need and I don't know how to combine this into one which will be work. My problem is that that I have csv file which is insert there also, It includes first two rows of texts that I don't want to shows and it have first column with date and time and others columns inlude measure values which is numbers. So I want with one button to insert multiple csv into uitable without first two rows and with second button I want plot them. Now what I have. I am using uigetfile with MultiSelect on, then when I use xlsread I am able to read data but I am not able select multiple csv.
  • [num,txt,raw] = xlsread(file);
  • (assignin('base', 'data', raw));
  • set(handles.uitable1, 'Data', raw);
  • setappdata(0,'table',raw);
second what I have is this, this one is usefule for skip the first two row but can't choose multiple csv file
  • T = readtable(file,'HeaderLines',1);
  • C = table2cell(T);
  • (assignin('base', 'data', C));
  • set(handles.uitable1, 'Data', C);
  • setappdata(0,'table',C);
third is this which can be use for multiple choise
  • ds = datastore(file);
  • mydata = readall(ds);
  • C = table2cell(mydata);
  • (assignin('base', 'data', C));
  • set(handles.uitable1, 'Data', C);
  • setappdata(0,'table',C);
in the second button I have this, it is work with my date and time type
  • table = getappdata(0, 'table');
  • str = convertCharsToStrings(table(:,1));
  • DateString = datestr(str);
  • DateNumber = datenum(DateString);
  • B.Var1 = datetime(DateNumber, 'convertFrom', 'datenum','Format', 'dd.MM.yy HH:mm');
  • data = str2double(table);
  • ydata1 = data(:,2);
  • axes(handles.axes1);
  • plot(B.Var1,ydata1,'--','Color','#4DBEEE');
So it is possible to use uigetfile and choose multiple csv file with date and time and numbers and skip the first two rows and insert them into uitable and with second button plot them from uitable. Thank you very much with some idea how to deal with this. I am already lost.

采纳的回答

Jalaj Gambhir
Jalaj Gambhir 2020-4-7
Hi,
First of all, for your problem, I would recommend you to use App Designer instead of GUIDE as recommended here.
You need to break your problem into components.
  • Select multiple csv files, and read them individually.
This can be done using readTable as it provides flexibility to specify the number of header lines to be ignored, which is 2 in your case.
[filename, path] = uigetfile('*.csv','Select csv files','MultiSelect','on');
x = {}
for i = 1:length(filename)
data = readtable(fullfile(path,filename{i}), 'HeaderLines',2);
x{i} = data;
end
big_table = vertcat(x{:});
app.UITable.Data = big_table;
I created this in AppDesigner, button push callback function. This will help you read multiple csv files, ignore 2 header lines of each file and output the relevant data in a 'table' format. All these individual tables can then be merged into one big table, and used directly for displaying.
  • In your plotData callback, you can add your code to read the data from the UITable and plot it, using the code you have mentioned in your question.
Hope this helps!
  3 个评论
Jalaj Gambhir
Jalaj Gambhir 2020-4-13
Are you saying that in GUIDE, for the same csv file, readtable is working perfectly while in AppDesigner it is not? I doubt that might be the case.
Sarlota Duskova
Sarlota Duskova 2020-4-14
编辑:Sarlota Duskova 2020-4-16
I am apologize, it is my bad. I did this and now it is working fine:
  • data = readtable(fullfile(path,filename{i}), 'Delimiter', '\t ;', 'MultipleDelimsAsOne', true);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by