Plotting two 3D points from a textscan output
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Tom
el 28 de Oct. de 2013
Comentada: sixwwwwww
el 29 de Oct. de 2013
I have the following text file:
Eu3+ 1
10.06037350 -4.673610300 -1.834337367
1.22604929765 -2.02696902730 0.734136756877
10517.3113705 -9795.46057045 -2441.96899290
Eu3+ 2
-11.25268764 3.982158778 -4.411302032
0.239696547775E-01 0.719865908056 0.654664578760
-3423.27694546 -2308.86356341 -348.027397200
Whereby the entries are to be considered as (1) atom type (2) atom number (3)(4)(5) xyz coordinates (6)(7)(8)(9)(10)(11) irrelevant, and then repeated. I want to be able to represent a huge list of such data entries as atom positions and ultimately perform further calculations upon them, but currently I am only able to plot a single atom, using this code:
fid = fopen('twoatom.txt','r'); %read as a single cell
A = textscan(fid,'%s'); %perform textscan
A = A{1,1}(1:5); %Attain data as 1x5 cell array
a1 = A(1,:); %Atom type to vector
a2=str2double(A(2:end,:)); %Atom coordinates to vector
scatter3(a2(2),a2(3),a2(4))
But I have already had to ask for quite a bit of help to get this far, and am struggling to extend the code to accommodate a second atom. Could anyone enlighten me as to how this would be done? I am hoping that if someone can I will be able to extend the code myself to accommodate every atom in the file.
Any help would be greatly appreciated.
Kind regards,
Tom
1 comentario
Respuesta aceptada
sixwwwwww
el 28 de Oct. de 2013
Dear Tom, you can do it as follows:
ID = fopen('filename.txt', 'r');
data = textscan(ID, '%s');
fclose(ID);
data = data{:};
atom_type = data(1:11:length(data));
atom_number = str2double(data(2:11:length(data)));
count = 1;
for i = 3:11:length(data)
xyz(count, :) = str2double(data(i:i+2));
count = count + 1;
end
scatter3(xyz(:,1), xyz(:,2), xyz(:,3));
I hope it helps. Good luck!
6 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Export en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!