Replace a matrix on a text file
Mostrar comentarios más antiguos
Hello everyone,
Few months ago I have done with the help of the forum a matlab code that extract a specific part of a 100 000+ rows text file as a matrix.
Using this matrix of 5 columns, I have created a "result" vector (called B) where values are numbers.
I would like to modify the part of the text file containing the initial matrix and replace it with my result vector which has the same number of rows but 1 column. Writematrix doesn't seem to work for specific location ?
So to be clear :
How can I replace an existing (n,5) matrix by a (n,1) at a specific location (that is known)?
Thanks for any help! If you like I can give you the file that is analysed to see how it works
Matt
Here is my code.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%A wannabe Code to read the t19 result file from Marc/Mentat and extract stress matrix (part1)
%Then, Calculate the Dang van criterion for critical element.
% Matthieu Aoun,
% 01/22
clc
clear all
starter='=beg=52300 (Element Integration Point Values) '; %start of the matrix of interest
ender='=beg=52401 (Nodal Results) '; %end of the matrix of interest
% Material Properties
% Material_name='Aluminium Al6061';
% E=640000;
sr0=94; %tensile endurance limit released R=0
sr1=102; %tensile Endurance limit fully reversed R=-1
alpha=(3/2)*(sr1-sr0)/(2*sr0-sr1); % for tension/compression values
beta=(sr1*sr0)/(2*sr0-sr1); % for tension/compression values
% alpha = 0.232; % for bending/torsion
% beta = sr1*0.577; % for bending/torsion
xmax=beta/alpha;
try %if no error
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% matrix : Hydrostatic Stress, Von Mises, Sigma 1, Sigma 2, Sigma 3, Strain
% % column 1 2 3 4 5 6
% CREATION OF RESULT MATRIX %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
file = 'G:\\Matthieu\\Job5\\topo1\\strut2\\file9\\marc9_job1.t19';
A = textscan(fopen(file),'%s','delimiter', '\n'); %import file
stressloc1=find(strcmp(A{1,1},starter))+1 ; %location of the beginning of the matrix
stressloc2=find(strcmp(A{1,1},ender))-2 ; %location of the end of the matrix
range=stressloc2-stressloc1+1 ; %N of rows
opt = detectImportOptions(file, 'FileType','fixedwidth', 'VariableWidths',13*ones(1,6), 'ReadVariableNames',false);
opt.DataLines = [stressloc1,stressloc2];
%normal stresses and shear stress matrix
nstress = readmatrix(file,opt); nstress = nstress(:,1:5) ;
stresses(:,1)=abs((nstress(:,3)-nstress(:,5))*0.5); %tau13
stresses(:,2)=abs((nstress(:,4)-nstress(:,5))*0.5); %tau23
stresses(:,3)=abs((nstress(:,3)-nstress(:,4))*0.5); %tau12
stresses(:,4)=(nstress(:,3)+nstress(:,4)+nstress(:,5))/3; %sigmahydrosatic
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DANG VAN CRITERION %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
maxnstress=max(stresses(:,4));
maxshear=max(stresses(:,1));
B=stresses(:,1)+alpha*stresses(:,4);
safety=beta/max(B(:,1));
min_safety_el_id = find(B==max(B(:,1)))+10;
max_stress_el_id = find(stresses(:,4)==maxnstress)+10;
result_mat(count,1)=count; %USER RESULT
result_mat(count,2)=safety;
result_mat(count,3)=min_safety_el_id;
result_mat(count,4)=max_stress_el_id;
result_mat(count,5)=maxnstress;
result_mat(count,6)=maxshear;
catch %if error
% skip this iteration
end
%%
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!