How is it possible to slice up a table into smaller ones if the data contains floating point numbers?

Hello everyone,
As seen in the attachment I have generated a stacked table with 3 columns and 19000 rows. The columns represent the cartesian coordinates x, y and z and the rows are the according data points. This table will be used as a 3D printer path description for a set of curves (Each curve is "stacked" on each other).
Upon a closer look you will notice that the x values from -75 to 75 are repeating themselves in regular intervals but their row range is totally different due to the fact that these are purely floating numbers generated by a function. (It was important for me to increase the density of data point in some areas and lower the density of data points in other areas)
Therefore I would like to perform the following tasks:
1.) I want to slice up this stacked data table into smaller ones. The criteria for this slicing operation should be the x values from -75 to 75 because the row range varies for each curve. (Therefore each table contains a different amount a data points but they all start from -75 and end with 75).
e.g
1st small Table:
X Y Z
( Amount of data points of each cartesian coordinate: e.g 1557)
2nd small Table:
X Y Z
( Amount of data points of each cartesian coordinate e.g 1241)
3rd small Table:
X Y Z
( Amount of data points of each cartesian coordinate: e.g 1287)
... etc.
2.) I want to insert two text messages above and under each table (e.g text) without the appearance of '' in the table
I have already tried the conservative approach with repshape and unique but it does not work for floating number. The reason for this is because this commands rely on an even row numbers...
I would like to know if somebody i much more keen on the commands/methods regarding this topic since I am still a beginner in matlab. Hence I would like to have a code for this matter.
Stay safe and healthy
David

 Réponse acceptée

ix=find(diff(XYZ(:,1))<0);
will locate the breakpoints where the X coordinate resets.
Remember diff(x) contains one less point in it than does (x) owing to having taken the difference so ix will be the index of the last element of each segment; ix+1 will give the beginning of the next segment.

7 commentaires

Wow. Never imagined this to be that easy. I tested it out with this code on the first column:
data = data(:,1);
ix=find(diff(data(:,1))<0);
and it produced the breakpoint locations.
I still have yet to obtain the code so I would like to ask you if this could could work for constructing the smaller tables:
counter = height(ix)-1;
% Total amount of breakpoints to stop while loop, but first one is not included
table_1st = data(1:ix(1,:));
% Wanted to extract the first row until the first breakpoint
while counter > 0
i = 1
table_n = data(ix(1+i,:):ix(1+2i,:));
% Wanted to extract the 2nd till the 3rd breakpoint and so on...
% n should increase but I am unsure how to apply the string...
counter = counter - i;
end
Well here I am stuck with the loop and the 2nd question...
i2=find(diff(XYZ(:,1))<0); % end breakpoints
i2=[i2; size(XYZ,1)]; % augment w/ end
i1=[1; i2(1:end-1)+1]; % starting points (end + 1)
for i=1:numel(i1) % iterate over number sections
dataset(i)={XYZ(i1:i2,:)}; % use cell array for each section
end
This method is perfect. Especially the storing of the data sets in cells. Thank you very much!
I have just one little question. Could you expand your code by adding a text message (START_PRINT and END_PRINT) above and under each section, please?. This would be great in order to execute my 3d printing makro.
I found a solution:
cellsize = size(dataset);
cellsize_max = max(cellsize);
celltext_above = transpose(repelem([{'StartCurve'}], [cellsize_max])');
celltext_under = transpose(repelem([{'EndCurve'}], [cellsize_max])');
DATA = {celltext_above; Importset; celltext_above};
That puts all the Start and Stop strings at the head and tail altogether...
Is the need just a display or to embed the string (eventually) into a file?
The purpose was actually to create a cell array with a certain amount of columns and 3 rows. The first row should contain a repetition of first text. the middle test contains the data itself and the third row the 2nd repetition of the text.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by