Get data from xls file.

3 Ansichten (letzte 30 Tage)
Matin jaberi
Matin jaberi am 12 Jul. 2022
Bearbeitet: Matin jaberi am 22 Jul. 2022
Hi Everyone, Im a newbie to Matlab. I have a table of 105216x10 in my workspace which i need to get some data from. its only numbers in the table.
In A column i have numbers from 1-15 wheere some are repeated. I only am interested in the rows when in clumn A changes from 6 to7. so basically if number =6 and the number fater is 7 then print that row
have following code but only returns 1.
number6=1;number7=1;
for i=1:length(data)
if data(i,1) == 7 && i-1 == 6
newT(number6) = AA(i-1,:) ;number6 = number6+1 ;
end
if data(i,1) == 8 && i-1 == 7
DDD(number7) = AA(i-1,:) ;number7 = number7+1 ;
end
end
Thanks
Ex

Antworten (1)

Adam Danz
Adam Danz am 12 Jul. 2022
Bearbeitet: Adam Danz am 13 Jul. 2022
> i need a comand to check the numbers in column A and anywhere that 6 change to 7 show me the entire rows for last 6 and where 7 changes back to 6 show me the last row in 7.
Here's a demo
Create demo table
Produce table T with variable names A,B.
A = [4;5;6;6;7;7;8;6;6;6;5;7;7;6;6;7;7;6;6;7;7];
B = round(rand(size(A))*10,2);
T = table(A,B);
disp(T)
A B _ ____ 4 1.68 5 8.06 6 0.2 6 0.5 7 0.63 7 5.7 8 1.09 6 8.34 6 9.71 6 6.51 5 8.87 7 6.4 7 8.13 6 2.87 6 2.68 7 1.88 7 9.4 6 3.65 6 0.4 7 7.01 7 4.51
Find index of the last 6 that changes to 7 and the last 7 that changes to 6
dA = [diff(T.A);0];
isLastSix = T.A==6 & dA==1; % bad variable name, change it
isLastSeven = T.A==7 & dA==-1; % bad variable name, change it
Show rows of table for each index
T(isLastSix,:)
ans = 3×2 table
A B _ ____ 6 0.5 6 2.68 6 0.4
T(isLastSeven,:)
ans = 2×2 table
A B _ ____ 7 8.13 7 9.4

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by