Splitting up large amount of data into smaller tables based on one coloumn
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
clear all; close all;
% x = x, y = y, r= raman shift, i = intensity
[x] = textread('rawData.txt');
y=size(x);
rv=length(x);% rv = raman shift value
B1=zeros(rv,4);
for c=1:1:rv-1;
for i=1:4;
if x(c,3)>x(c+1,3)
B1(c,i)=x(c,i);
B1=B1+1;
elseif x(c,3)<x(c+1,3);
B1(c,i)=x(c,i);
B1=B1+1;
end
end
end
Hi all this is my current code, i have a very large data set comprised of 4 coloumns, and i need to seperate it when a value in the third coloumn is smaller than the next value. The number of values between this happening is not consistent, but i need to seperate it out into lots of tables of the 4 coloumns
Any help would be greatly appreciated!!
0 comentarios
Respuestas (2)
Bob Thompson
el 12 de Feb. de 2019
Editada: Bob Thompson
el 12 de Feb. de 2019
Hmm, I think I kind of understand what you are trying to do. Let me know if this works.
mark = 1;
cll = 1;
for i = 2:size(x,1)
if x(i,3) > x(i-1,3);
tests{cll} = x(mark:i,:);
cll = cll + 1;
mark = i;
end
end
This should look for the different breaks, and record the different data sets into cells in 'tests'.
2 comentarios
Peter Perkins
el 25 de Feb. de 2019
You have not said why you want to do that, but in general, you DON'T want to split one table up into lots of tables. You will usually find that less convenient than just haivng an indicator variable in your one table.
In any case, to create that indicator, you don't need loops. Find the changepoints, and cumsum:
>> t = array2table(rand(10,3))
t =
10×3 table
Var1 Var2 Var3
_________ _______ ________
0.10665 0.43141 0.85303
0.9619 0.91065 0.62206
0.0046342 0.18185 0.35095
0.77491 0.2638 0.51325
0.8173 0.14554 0.40181
0.86869 0.13607 0.075967
0.084436 0.86929 0.23992
0.39978 0.5797 0.12332
0.25987 0.54986 0.18391
0.80007 0.14495 0.23995
>> t.Indicator = cumsum([true; t.Var3(2:end) > t.Var3(1:end-1)])
t =
10×4 table
Var1 Var2 Var3 Indicator
_________ _______ ________ _________
0.10665 0.43141 0.85303 1
0.9619 0.91065 0.62206 1
0.0046342 0.18185 0.35095 1
0.77491 0.2638 0.51325 2
0.8173 0.14554 0.40181 2
0.86869 0.13607 0.075967 2
0.084436 0.86929 0.23992 3
0.39978 0.5797 0.12332 3
0.25987 0.54986 0.18391 4
0.80007 0.14495 0.23995 5
2 comentarios
Peter Perkins
el 11 de Mzo. de 2019
n = 5;
c = cell(n,1);
for i = 1:n
c{i} = t(t.Indicator==i,1:3);
end
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!