how to convert a .txt file into a .xls file in matlab?

3 ビュー (過去 30 日間)
Cordelle
Cordelle 2013 年 6 月 18 日
コメント済み: Guillaume 2017 年 3 月 17 日
I suspect that I can actually read the log file data directly into Matlab without conversion. It is just a comma separated variable format(.csv), I believe, and I think it should be accessible to some Matlab input routine.
However,I dont not know the matlab input routine; It would be very helpful if someone can enlighten me on the input routine
thanks in advance, Cordelle

回答 (3 件)

Jan
Jan 2013 年 6 月 18 日
This is not enough information to give a more explicit answer than:
  • Import the file by e.g. importdata or fopen / fscanf.
  • Export the data by xlswrite.
I suggest to add mire details, e.g. the file's contents by editing the original question (not as comment or answer).
  2 件のコメント
Cordelle
Cordelle 2013 年 6 月 18 日
編集済み: Cordelle 2013 年 6 月 18 日
When I imported the file using importdata this occured:
data: 3
textdata: {863x4 cell}
what does this mean? and how can I convert the imported file into an excel file?
Iain
Iain 2013 年 6 月 18 日
編集済み: Iain 2013 年 6 月 18 日
That means that data is a structure containg the field "textdata", and that "textdata" contains a cell array (each element of a cell array can be a different type of number, string, or even another array).
Try:
xlswrite('myxl.xls',data.textdata)
winopen('myxl.xls')

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


Shashank Prasanna
Shashank Prasanna 2013 年 6 月 18 日
That means its a cell in a structure.
You can access data from structures:
and use
If you need editing in between you should do that.
If you are unfamiliar with cell and structures at all in MATLAB, I point you to
  3 件のコメント
Shashank Prasanna
Shashank Prasanna 2013 年 6 月 18 日
Jan
Jan 2013 年 6 月 18 日
Please do not post explanations like "I used the "Load" input routine", but the corresponding code. This will reduce misunderstandings. Thanks.

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


Harish TV
Harish TV 2017 年 3 月 17 日
clear; clear all; fileip='filename.csv'; g=char(fileip); g=g(1:end-4) fileop=horzcat(g,'.xlsx') g=fileip(1:end-4); [~,~,F]=xlsread(fileip); F=cellstr(F); %delete the header rows (4 rows) F([1:4],:)=[]; for a=1:size(F,1); b=F(a,1); c=char(b); D(a,:)=strsplit(c,','); end xlswrite(fileop,D); disp(['--------------Process complete---------------------']);
  1 件のコメント
Guillaume
Guillaume 2017 年 3 月 17 日
There's a {}Format button to format code as such. That would make your post more readable.
g = char(fileip);
is a no-op. fileip is already char. In any case,
[path, basename] = fileparts(fileip);
fileop = fullfile(path, [basename, '.xlsx']);
would be a lot simple and safer.
F = cellstr(F);
is also a no-op. F is already a cell array. Same for
c = char(b); %b is already char.
In any case, the code is not going to work. It only writes the first column of the csv file. (hint: xlsread already does the splitting at the comma)

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by