
how to separate a 3D shape with repetitions to each repetition
    5 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Hello, I have a data of figure eight shape with repetitions (many times figure eight shape in the same data) [3X6140 array [x,y,z] for the rows]. I need to separate each figure eight for itself, I need to know the index for where the first shape start and where it ends and where the next one start and ends and so on. for example, I attach the mat file named matrix AND a figure of it.
Thanks.

0 commentaires
Réponse acceptée
  Image Analyst
      
      
 le 16 Sep 2018
        Try this:
clc;    % Clear the command window.
clearvars;
close all;  % Close all figures (except those of imtool.)
workspace;  % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
s = load('matrix.mat')
FE = s.FE
x = FE(1, :);
y = FE(2, :);
z = FE(3, :);
subplot(2, 2, 1);
plot3(x, y, z, 'b.');
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
zlabel('Z', 'FontSize', fontSize);
grid on;
title('Original Single Curve', 'FontSize', fontSize);
numPoints = length(x)
% Find distances from starting point.
distances = sqrt((x - x(1)).^ 2 + (y - y(1)).^ 2 +(z - z(1)).^ 2);
subplot(2, 2, 2);
plot(distances);
xlabel('Index', 'FontSize', fontSize);
ylabel('Distance from point 1', 'FontSize', fontSize);
% Find valleys by finding peaks of inverted signal.
[peakValues, indexesOfPeaks] = findpeaks(-distances);
peakValues = -peakValues; % Invert again.
% Add on very first and very last points
indexesOfPeaks = [1, indexesOfPeaks, numPoints];
peakValues = [distances(1), peakValues, distances(end)];
hold on;
plot(indexesOfPeaks, peakValues, 'rv');
grid on;
title('Distances from point #1', 'FontSize', fontSize);
% Extract out each part of the curve
subplot(2, 2, 3:4);
curveCount = 0;
for k = 1 : 2 : length(indexesOfPeaks) - 1
  index1 = indexesOfPeaks(k);
  index2 = indexesOfPeaks(k + 2) - 1;
  fprintf('Extracting points %d to %d.\n', index1, index2);
  xSingles{k} = x(index1:index2);
  ySingles{k} = y(index1:index2);
  zSingles{k} = z(index1:index2);
  plot3(xSingles{k}, ySingles{k}, zSingles{k}, '-', 'LineWidth', 2);
  hold on;
  curveCount = curveCount + 1;
end
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
zlabel('Z', 'FontSize', fontSize);
caption = sprintf('%d curves', curveCount);
title(caption, 'FontSize', 20);
grid on;

Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Histograms dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

