How to resolve the error
Mostrar comentarios más antiguos
Unable to perform assignment because the size of the left
side is 39978-by-1 and the size of the right side is
39987-by-1.
Error in Stress_analysis (line 46)
coordinate_all(:,i,j) = C{1,j};
Code is here.
%% Read dump file
clc, clear, close all
disp('A script to deal with the dump file of lammps.');
tic;
%% Set up some parameters related to the dump file
% Inpute / Output file name
in_file = 'D:\NewWorkPost18May2023\DSC\PPT_Data\DumpFiles\Thin_Film\SiO2-Cr-Au\BeforeAnnealing\atom_300K.dump'; % Dump file name
save_file_name_1 = 'coordinate_all.mat'; % Output file for coordinate data
% Read the information of the simulation box in the dump file
fileID = fopen(in_file, 'r');
atoms = textscan(fileID, '%n', 1, 'HeaderLines', 3, 'Delimiter', '\t'); % Number of particles (You should read the textscan command carefully)
box = textscan(fileID, '%n %n', 3, 'HeaderLines', 2, 'Delimiter', '\t'); % Extract box information
fclose(fileID);
Total_atoms = 39978; % Number of atoms
len_header = 9; % Skip comments (may have to change acording to your system )
N = Total_atoms + len_header; % Length of block
%% Parameters from MD simulation
Output_interval = 100000; % Dump output interval (step)
Total_running_steps = 1000000; % The total number of running steps of lammps during the production period
Ns = Total_running_steps / Output_interval; % Total number of dump point (number of frames)
% If you have more output (columns) in your dump file, you must modify this value
dump_columns = 14; % The number of columns in the dump file (Modify according to your own output)
%% Deal with data
coordinate_all = zeros(Total_atoms, dump_columns, Ns);
fileID = fopen(in_file);
form = '%f ';
formatSpec = repmat(form, 1, dump_columns); % Equivalent to the number of dump_columns = x
for i = 1:Ns
C = textscan(fileID, formatSpec, N, 'HeaderLines', len_header, 'Delimiter', '\t');
for j = 1 : dump_columns
coordinate_all(:,i,j) = C{1,j}; % Extract all the coordinate information (Including all frames)
% Of course, it can also contain only the information you want (need to modify)
end
end
fclose(fileID);
save(save_file_name_1, 'coordinate_all')
frame_traversala = coordinate_all(:, :, 5);
frame_traversalb = coordinate_all(:, :, 6);
frame_traversalc = coordinate_all(:, :, 7);
frame_traversald = coordinate_all(:, :, 8);
frame_traversale = coordinate_all(:, :, 9);
frame_traversalf = coordinate_all(:, :, 10); % For test
%%%%% data processing %%%%%%
frame_traversala(:,1:4)= [];
frame_traversala(:,2:7)= [];
frame_traversala(:,3:4)= [];
Ba = sortrows(frame_traversala,1);
Ba(:,2) = 0.0001*Ba(:,2); % pzz in GPa
pressurea = Ba(:,2);
deptha = Ba(:,1);
frame_traversalb(:,1:4)= [];
frame_traversalb(:,2:7)= [];
frame_traversalb(:,3:4)= [];
Bb = sortrows(frame_traversalb,1);
Bb(:,2) = 0.0001*Bb(:,2); % pzz in GPa
pressureb = Bb(:,2);
depthb = Bb(:,1);
frame_traversalc(:,1:4)= [];
frame_traversalc(:,2:7)= [];
frame_traversalc(:,3:4)= [];
Bc = sortrows(frame_traversalc,1);
Bc(:,2) = 0.0001*Bc(:,2); % pzz in GPa
pressurec = Bc(:,2);
depthc = Bc(:,1);
frame_traversald(:,1:4)= [];
frame_traversald(:,2:7)= [];
frame_traversald(:,3:4)= [];
Bd = sortrows(frame_traversald,1);
Bd(:,2) = 0.0001*Bd(:,2); % pzz in GPa
pressured = Bd(:,2);
depthd = Bd(:,1);
frame_traversale(:,1:4)= [];
frame_traversale(:,2:7)= [];
frame_traversale(:,3:4)= [];
Be = sortrows(frame_traversale,1);
Be(:,2) = 0.0001*Be(:,2); % pzz in GPa
pressuree = Be(:,2);
depthe = Be(:,1);
frame_traversalf(:,1:4)= [];
frame_traversalf(:,2:7)= [];
frame_traversalf(:,3:4)= [];
Bf = sortrows(frame_traversalf,1);
Bf(:,2) = 0.0001*Bf(:,2); % pzz in GPa
pressuref = Bf(:,2);
depthf = Bf(:,1);
depth = [deptha depthb depthc depthd depthe depthf];
pressure = [pressurea pressureb pressurec pressured pressuree pressuref];
depth = mean(depth,2);
pressure = mean(pressure,2);
plot(depth,pressure);
%%%%%% binning%%%%%%%%%%%%%%%
edges = (-9.8:0.5:128);
[~,~,loc]=histcounts(depth,edges);
meany = accumarray(loc(:),pressure(:))./accumarray(loc(:),1);
xmid = 0.5*(edges(1:end-1)+edges(2:end));
figure
hold on;
plot(xmid,meany,'r')
%%
Respuestas (1)
You have indexed a set of rows that is different in size from the number of elements you are trying to assign to it. They must be the same size.
A = [1;2];
A(:,1) = (1:3)'
2 comentarios
Tejasva Vashistha
el 10 de Ag. de 2023
The issue is exactly the same as the example code I shared above. For some reason, your variable C is not the size you are expecting it to be. Your options are to adjust the row assignment in coordinate_all to match the size of C, or adjust the rows of C you are assignment to match the size of coordinate_all.
For the example above, you could do this.
A = [1;2];
B = (1:3)';
A(:,1) = B(1:size(A,1),1)
% or
A(1:size(B,1),1) = B(:,1)
You need to decide which approach is best for you application.
Categorías
Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!