Eliminating and creating new data file
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all, I have data which has information for different events, each event has 5 row information. I just want to eliminate this data and delete all of 5 line for that event with respect to some criteria and to create new data file without eleminated data.
A = xlsread('example.xls');
M = cell(1, length(4:5:size(A,1))); %Preallocate M for speed
Miso = cell(1,length(4:5:size(A,1))); %Preallocate Miso for speed
isoratio = cell(1,length(4:5:size(A,1))); %Preallocate isoratio for speed
j = 1; q=1; v=1;
for i= 4:5:size(A,1)
Mrr=A(i,2)*10^A(i,1);
Mtt=A(i,4)*10^A(i,1);
Mpp=A(i,6)*10^A(i,1);
Mrt=A(i,8)*10^A(i,1);
Mrp=A(i,10)*10^A(i,1);
Mtp=A(i,12)*10^A(i,1);
%%%build the given full moment tensor%%%
M{j} = [Mrr Mrt Mrp; Mrt Mtt Mtp; Mrp Mtp Mpp];
Miso{q}=(trace(M{j}/3)*eye(3,3));
isoratio{v} = norm(Miso{q},'fro')/(norm(M{j},'fro'));
j = j + 1;
q = q + 1;
if isoratio{v} > 10e-17;
fprintf('isoratio > 10e-17 \n');
end
v = v + 1;
end
For example in this case I defined isoratio for each event, and the program should delete all 5 line information about that event and write 5 line information of each event with isoratio value bigger than 10e-17 to new xlsx or txt file.
Is there any advice for this code ? I attached data file to this post. Thanks in advance for your interest.
2 commentaires
Réponses (1)
Jan
le 4 Juin 2018
Modifié(e) : Jan
le 4 Juin 2018
An advice:
Compare:
Mrr=A(i,2)*10^A(i,1);
Mtt=A(i,4)*10^A(i,1);
Mpp=A(i,6)*10^A(i,1);
Mrt=A(i,8)*10^A(i,1);
Mrp=A(i,10)*10^A(i,1);
Mtp=A(i,12)*10^A(i,1);
M{j} = [Mrr Mrt Mrp; Mrt Mtt Mtp; Mrp Mtp Mpp];
with
index = [2, 8, 10; 8, 4, 12; 10, 12, 6]; % Before the loop
M{j} = reshape(A(i, index), 3, 3) *10^A(i,1);
length(4:5:size(A,1)) is a waste of time. Use this once:
len = floor((size(A, 1) - 4) / 5) - 1
0 commentaires
Voir également
Catégories
En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!