Error reading mutiple files with 'importdata'-Loop

1 回表示 (過去 30 日間)
Mark
Mark 2017 年 11 月 1 日
コメント済み: Mark 2017 年 11 月 1 日
Hi, I'm trying to develop a GUI for some image processing. I'm already stuck at reading in the 'raw' .csv files. My code for importing the data so far:
[flnm,flpth,cCheck] = uigetfile('*.csv',...
'Select the Data File',...
'Multiselect','on');
if (cCheck ~= 0)
set(handles.List,'Value',1);
set(handles.List,'String',flnm);
end
z = size(flnm);
z = z(1,2);
Store = rand (511,640,z);
delimiterIn = ',';
headersIn = 530;
Raw = cell(530,z);
for s =1:z
Raw(:,s) = importdata(flnm{s,1},delimiterIn,headersIn);
Raw(:,s) = strrep(Raw(:,s), ',','.');
Raw(:,s) = strrep(Raw(:,s), ';',' ');
end
In this case the result of the import data function is a 530 by 1 column-vector. I want to store mutiple of these in the cell-array 'Raw'. Unfortunately the 'importdata-Loop' just works in its first iteration -> just the first column of the 'Raw' got filled.
The following Error appears:
Index exceeds matrix dimensions.
Error in SlideGui>pushbutton1_Callback (line 126)
Raw(:,s) = importdata(flnm{s,1},delimiterIn,headersIn);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in SlideGui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)SlideGui('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Has anybody an idea why the Loop index exceeds the dimension of any matrix?
Thanks a lot, Mark

採用された回答

Henrik Jacobsen
Henrik Jacobsen 2017 年 11 月 1 日
I think it's the size of flnm.
z = size(flnm);
z = z(1,2);
This indicates that flnm is a row of filenames. But
importdata(flnm{s,1},delimiterIn,headersIn);
indicates that it is a column. Try
importdata(flnm{1,s},delimiterIn,headersIn);
  1 件のコメント
Mark
Mark 2017 年 11 月 1 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by