Eliminating and creating new data file

5 Ansichten (letzte 30 Tage)
Gökçe Öter
Gökçe Öter am 31 Mai 2018
Bearbeitet: Jan am 4 Jun. 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 Kommentare
Gökçe Öter
Gökçe Öter am 1 Jun. 2018
Bearbeitet: Gökçe Öter am 1 Jun. 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 :)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 4 Jun. 2018
Bearbeitet: Jan am 4 Jun. 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

Kategorien

Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by