Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Help with textscan classifier

조회 수: 1 (최근 30일)
Tom
Tom 2013년 10월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello,
Trying to extract data from a text file, the data is in the format:
Eu3+ 1 10.06037350 -4.673610300 -1.834337367
Currently I am trying C = textscan(fid,'%s%d8%f32%f32%f32');
However this returns: C = {1x1 cell} [1] [10.0604] [-4.6736] [-1.8343]
So can anyone tell me what classifier I would need for the Eu3+ entry?
Many thanks,
Tom
  댓글 수: 2
Simon
Simon 2013년 10월 24일
Hi!
What's wrong with the result? What is "Eu3+"? Is it a string?
Tom
Tom 2013년 10월 24일
Eu3+ 'physically' refers to an atom type (europium), and the numbers which follow are x y z coordinates. The text file contains an enormous list of a few different atom types and their coordinates, so I presumed the output would return 'Eu3+' and not just [1x1 cell] so I could later refer to the following coordinates as corresponding to that atom type.
... sorry if that doesn't answer your question. I'm struggling after a long period from Matlab.

답변 (2개)

Neil Caithness
Neil Caithness 2013년 10월 24일
Your current output does seem to be what you want.
str = 'Eu3+ 1 10.06037350 -4.673610300 -1.834337367';
C = textscan(str,'%s%d8%f32%f32%f32')
C =
{1x1 cell} [1] [10.0604] [-4.6736] [-1.8343]
Look at the contents of the first cell:
C{1}
ans =
'Eu3+'

Simon
Simon 2013년 10월 25일
Hi!
You can write
C{1} = char(C{1});
This way you get a character array with each line corresponding to an atom type.
Or you can create a new cell array from C
Cnew = cell(length(C{1}), 5);
% loop over all rows
for r = 1:length(C{1})
% loop over all columns
for c = 1:5
if c == 1
% atom type as string
Cnew {r, c} = char(C{c}(r));
else
Cnew {r, c} = C{c}(r);
end
end
end

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by