Borrar filtros
Borrar filtros

Splitting up large amount of data into smaller tables based on one coloumn

4 visualizaciones (últimos 30 días)
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!!

Respuestas (2)

Bob Thompson
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
pillowheaded
pillowheaded el 13 de Feb. de 2019
Thank you so much that has done exactly what i need it to!
pillowheaded
pillowheaded el 22 de Feb. de 2019
Hi
I have been using the code you wrote and realised that it misses out the last block of data is there anyway to add additional lines of code to ensure it copies all the data?
thank you for your help

Iniciar sesión para comentar.


Peter Perkins
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
pillowheaded
pillowheaded el 27 de Feb. de 2019
Hi thank you for your answer,
the reason i want to do this is my data is a series of scans taken at various points but instead of the data being individual files the output is they are all stacked into one giant table with 4 coloumns.
i see what you have done and i like it but it is more benifical to me to have them split up as i then go on to fit peaks as each set of data is a spectre.
how would i use this code to then divide up the data?
Peter Perkins
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

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by