Counting numbers in a sequence while corrosponding to another sequence
Mostrar comentarios más antiguos
I am struggling to produce code for this problem where I am looking to count numbers in a sequence with their corrosponding intervals of another sequence. It is best shown wtih an example.
For example coloumn A is in thickness (m) and column B is in a sequence of 6 numbers (1-6). What I am trying to do is measure the thickness of each sequence in A with the corrsponding separate, seqeunce number in B (e.g 6 or 1) and how often they occur; then output a values for the thickness and frequency so they can be plotted on a histogram.
Column A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14] (metre intervals)
Column B=[6 6 6 6 4 4 4 2 2 6 6 4 4 4]
so for this sequence 6 occurs with a corrosponding thickness of 3m and 1m, 4 occurs wtih a thicknesses of 2m and 1m and 2 occurs with a thickness of 1m.
Any help would be much appreciated! Thanks
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 7 de Jun. de 2013
I'm not sure how column A was used in getting those results, but this is best done with regionprops() in the Image Processing Toolbox, if you have it:
ColumnB=[6 6 6 6 4 4 4 2 2 6 6 4 4]
ub = unique(ColumnB) % Get unique numbers.
for k = ub
measurements = regionprops(ColumnB== k, 'Area');
allAreas = [measurements.Area]-1;
fprintf('For %d, the area = ', k);
fprintf('%d, ', allAreas);
fprintf('\n\n');
end
In the command window:
ColumnB =
6 6 6 6 4 4 4 2 2 6 6 4 4
For 2, the area = 1,
For 4, the area = 2, 1,
For 6, the area = 3, 1,
1 comentario
oli8819
el 7 de Jun. de 2013
Andrei Bobrov
el 10 de Jun. de 2013
A=[1 2 3 4 5 6 8 9 10 11 12 13 14];
B=[6 6 6 6 4 4 4 2 2 6 6 4 4];
t = [true;diff(B(:))~=0];
out = [B(t).',accumarray(cumsum(t),A(:),[],@(x)x(end)-x(1))];
Categorías
Más información sobre Audio and Video Data en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!