Converting cell array with various entry types

1 回表示 (過去 30 日間)
Tom
Tom 2013 年 10 月 28 日
コメント済み: Tom 2013 年 10 月 28 日
Hello, I have the following lines of code:
fid = fopen('singleatom.txt','r'); %read as a single cell
C = textscan(fid,'%s');
fclose(fid);
C = C{1,1}(1:5)
which produces the following output:
C =
'Eu3+'
'1'
'10.06037350'
'-4.673610300'
'-1.834337367'
Could anyone explain to me how you would go about converting the cell array into a format where the data could be utilised, as this does not appear to be possible in its current form. The data represents:
C(1) = atom type
C(2) = atom number
C(3) = x-coordinate
C(4) = y-coordinate
C(5) = z-coordinate
So, for instance, how would I convert the data so that I could proceed to plot the atom's position on a scatter plot and label it with the identifiers?
Any assistance would be greatly appreciated.
Kind regards,
Tom

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 28 日
C ={'Eu3+' 'Eu4+'
'1' '2'
'10.06037350' '10.05026240'
'-4.673610300' '-5.562509200'
'-1.834337367' '-2.945448478'}
% you have the cells in the first line are char type
a1=C(1,:)
% the other cells are double type
a2=str2double(C(2:end,:))
  1 件のコメント
Tom
Tom 2013 年 10 月 28 日
I think that's done the trick, thankyou Azzi!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by