Eliminating and creating new data file

3 visualizaciones (últimos 30 días)
Gökçe Öter
Gökçe Öter el 31 de Mayo de 2018
Editada: Jan el 4 de Jun. de 2018
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 comentarios
Gökçe Öter
Gökçe Öter el 1 de Jun. de 2018
Editada: Gökçe Öter el 1 de Jun. de 2018
Yes, but this one is not the same with the former one. In this case for loop is considered and calculation is the critical part to save new data file which I couldn't achieve :)

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 4 de Jun. de 2018
Editada: Jan el 4 de Jun. de 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

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by