Saving Imported Data automatically

Hi,
I am using below code to import data from .dat and .xlsx files. How I can save the imported data in two matrices. I mean .dat imported data save to matrix A and .xlsx imported data save to B matrix
[filename, pathname, filterindex] = uigetfile( ...
{ '*.mat','MAT-files (*.mat)'; ...
'*.slx;*.mdl','Models (*.slx, *.mdl)'; ...
'*.*', 'All Files (*.*)'}, ...
'Pick a file', ...
'MultiSelect', 'on');
Thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 11 月 19 日

0 投票

Because you have MultiSelect on, the returned filename will be a cell array of strings. You can loop over those taking one at a time and dealing with it:
for K = 1 : length(filename)
thisfilename = filename{K};
[~, ~, this_ext] = fileparts(thisfilename);
if strcmpi(this_ext, '.mat')
it is a .mat file. Process it
elseif strcmpi(this_ext, '.xlsx')
it is a .xlsx file, process it
else
oh oh, how did this happen? What to do now?
end
end

5 件のコメント

Ali Kareem
Ali Kareem 2015 年 11 月 19 日
Hi,
Thank you for your reply. When I am trying to execute code I got error
Undefined function or variable 'it'.
Undefined function or variable 'oh'.
Error in Open_Multifiles (line 16)
oh oh, how did this happen? What to do now?
Thanks
Stephen23
Stephen23 2015 年 11 月 19 日
Make that line a comment, it is not code that can run:
% oh oh, how did this happen?
Ali Kareem
Ali Kareem 2015 年 11 月 20 日
Hi,
Thank you for your reply. It is still not working?
Regards
Walter Roberson
Walter Roberson 2015 年 11 月 20 日
The lines "it is a .mat file. Process it", "it is a .xlsx file, process it" and "oh oh, how did this happen? What to do now?" are intended to be places that you replace with code specific to what you want to do with your files.
Ali Kareem
Ali Kareem 2015 年 11 月 20 日
Hi,
Thank you for your reply. I just want to import data using uigetfile and write the imported files in matrices so I can use it in my code?

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

カテゴリ

タグ

質問済み:

2015 年 11 月 19 日

コメント済み:

2015 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by