Splitting up large amount of data into smaller tables based on one coloumn
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Bob Thompson
2019-2-12
编辑:Bob Thompson
2019-2-12
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'.
Peter Perkins
2019-2-25
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!