Import an Excel File
古いコメントを表示
Hi,
I have given an Excel table. This Excel table I have imported with "Import Data" and saved as a cell array as "generate function". Now I want to asign the content of the imported file to a variable. Can I do that with: imp = importfile_1(file path of the created import file);
The problem is that it doesn't work atm. The entries in the variable are not equal to the excel entries.
At the end I want to have a two dimensional array with the entries of the Excel file.
I hope one of you can help me.
4 件のコメント
Cedric
2017 年 9 月 24 日
Can you attach a slice of the original file, and explain how you would like the content to be "split" (according to your comment to Azzi's answer) ultimately?
The problem is that none of us seems to understand what you are trying to achieve overall. So we should start from the beginning: if you are trying to read the content of a file and extract part of this content, could you attach this file to your post? The is a staple icon for this purpose in the editor. Then tell us what it is that you want to extract, and for what purpose.
mb12345
2017 年 9 月 25 日
採用された回答
その他の回答 (3 件)
Azzi Abdelmalek
2017 年 9 月 24 日
0 投票
Use xlsread function
3 件のコメント
mb12345
2017 年 9 月 24 日
Image Analyst
2017 年 9 月 24 日
To format the Excel worksheet before importing it into MATLAB, you need to use ActiveX. That will let you do things like format the font and how many decimal places are showing, etc.
mb12345
2017 年 9 月 24 日
Image Analyst
2017 年 9 月 24 日
Looks like you forgot the extension. Try:
fullFileName = 'C:\Users\UserX\Desktop\filetoopen.xlsx'
[~, ~, imp] = xlsread(fullFileName);
Or if the data has the same data type in every column, you could use readtable():
imp = readtable(fullFileName)
15 件のコメント
mb12345
2017 年 9 月 24 日
mb12345
2017 年 9 月 24 日
Image Analyst
2017 年 9 月 24 日
Well obviously you have to change "filetoopen" with the actual filename!
You're the one who gave that pseudocode name to it originally, not me, so I assumed you knew that.
OK, let's say your ACTUAL filename was "image analysis raw measurements.xlsx". So then you'd do
fullFileName = 'C:\Users\UserX\Desktop\image analysis raw measurements.xlsx'
[~, ~, imp] = xlsread(fullFileName);
Image Analyst
2017 年 9 月 24 日
Then what kind of file is your data IN? I was under the impressions it was in an Excel workbook file with a .xlsx extension. If it has nothing to do with Excel at all, then there are a variety of other functions you can use. You might be able to use several and it just depends on what your choice is. For example, maybe one or more of these will work: importdata, readtable, dlmread, csvread, fileread, fgetl, fread, textscan, fscanf, etc.
Walter Roberson
2017 年 9 月 24 日
You do not import code: you execute code. You use importdata to generate importfile.m and then you call
result = importfile('AppropriateDataFileNameGoesHere.txt');
mb12345
2017 年 9 月 25 日
Image Analyst
2017 年 9 月 25 日
So, what about xlsread(), like I showed, is not working? Attach an actual workbook if you want me to try to read it in for you.
Walter Roberson
2017 年 9 月 26 日
If you told it to generate code into filetoopen.m then to read your file whose name is stored in mystring then:
result = filetoopen(mystring);
Image Analyst
2017 年 9 月 26 日
Try
[~, strings, imp] = xlsread(fullFileName);
columnA = strings(:, 1); % Extract column 1 (A)
% Print words
for row = 1 : length(columnA)
thisString = columnA{k}
words = strsplit(thisString, ' ')
for w = 1 : length(words)
fprintf('In row #%d, word #%d = %s\n', row, w, words{w});
end
end
mb12345
2017 年 9 月 27 日
Walter Roberson
2017 年 9 月 27 日
Is C:\Users\UserX\Desktop on your MATLAB path?
And did you generate into filetoopen with no extension or into filetoopen.m ?
mb12345
2017 年 9 月 27 日
mb12345
2017 年 9 月 28 日
Ahsan Mehmood
2019 年 6 月 16 日
use length instead of len
カテゴリ
ヘルプ センター および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!