How to tabulate charge densities over 3D rectangular grid points

1 回表示 (過去 30 日間)
Anthony Owusu-Mensah
Anthony Owusu-Mensah 2020 年 2 月 24 日
編集済み: Anthony Owusu-Mensah 2020 年 2 月 27 日
I would want to tabulate some charge densities over a 3d rectangular grid.
I created the attached file from reading multiple files and extracting their columns
of interest. I use the script below to read the attached text file
Path = 'Input correct path';
filename = 'Input correct filename'
format='%5s%5s%5s%5.0f%8.3f%8.3f%8.3f%8.4f%8.4f%8.4f%[^\n\r]';
nAtoms = 52719;
fileID=fopen([path '/' filename]);
AllTraj=textscan...
(fileID, format, nAtoms, 'Delimiter', '', 'WhiteSpace', '', 'EmptyValue' ,NaN,'HeaderLines', readstartrow, 'ReturnOnError', false);
fclose(fileID);
AllPositionsx = AllTraj{:,5}; % x
AllPositionsy = AllTraj{:,6}; % y
AllPositionsz = AllTraj{:,7}; % z
Charge = AllTraj{:,8}; % charge
The first 3 columns of (PostionPlusCharge) are the x,y,z postions respectively and the last column is the charge
I would want to tabulate the charges over a 3d rectangular grid based on x,y and z postions.
for instance for the first row x = 1.4810, y = 1.4760 and z= 7.7810. The corresponding charge is -0.6.
I want to do say, matrix(x,y,z) = -0.6.
I tried using
for k = 1:length(x)
matrix(x(k),y(k),z(k)) = charge(k);
end
But the challenge is that, x,y and z are not integers.
  2 件のコメント
darova
darova 2020 年 2 月 24 日
Maybe interp3 or griddata is what you are looking for?
Anthony Owusu-Mensah
Anthony Owusu-Mensah 2020 年 2 月 26 日
編集済み: Anthony Owusu-Mensah 2020 年 2 月 26 日
I read the documentation. Seem not to be working for me. I used griddata and the resultant matrix has all NaN values

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

採用された回答

darova
darova 2020 年 2 月 26 日
Here is what i did
See attached script
  1 件のコメント
Anthony Owusu-Mensah
Anthony Owusu-Mensah 2020 年 2 月 27 日
編集済み: Anthony Owusu-Mensah 2020 年 2 月 27 日
Thanks Darova. Your solution has been an eye opener. I would extend it to all values of x, y and z. What was so informing is the use of the scatter3 to plot the scattered data.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNonlinear Dynamics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by