How to deal with nested arrays where the columns and rows are in different dimensions?

8 visualizzazioni (ultimi 30 giorni)
Hello everyone,
In some previous questions I have asked about defining a specific data structure which gave me splendid answers and a better understanding of organizing those data. Now, for a deeper meaning I would like to know the following:
I have a (72x1 cell) which content is defined by the following block/section:
COLUMN1
ROW1 Text Nr.1
ROW2 2345x3 double
ROW3 Text Nr.2
....times 24 to get the mentioned 72x1 cell array
My goal now is to unnest the 2345x3 double contents in a way, that I obtain the following data order:
COLUMN1 COLUMN2 COLUMN3
Text Nr.1 (empty) (empty)
value 1 value 1 value 1
value 2 value 2 value 2
value 3 value 3 value 3
value 4 value 4 value 4
value 5 value 5 value 5
value 6 value 6 value 6
value 7 value 7 value 7
etc. etc. etc.
Text Nr.2 (empty) (empty)
Text Nr.1 (empty) (empty)
value 1 value 1 value 1
value 2 value 2 value 2
value 3 value 3 value 3
value 4 value 4 value 4
value 5 value 5 value 5
value 6 value 6 value 6
value 7 value 7 value 7
etc. etc. etc.
Text Nr.2 (empty) (empty)
However this requires me to know about the new shifted positons without overwriting any data:
I tried to write a code with a (for loop?) but I am even unsure how to start nor to implement my thought process in a proper solution.
Hence I would like to know a method which allows me to unnest the above mentioned example into a cell array (N x 1) where N of course is the expanded version of the old nested cell array.
Stay safe and healthy,
David
Additional Notes:
For anyone asking about my intenton behind this question: I succesfully printed some parts in 3D printer yesterday using some of your answers by exporting those into different gcode converters which require different data structures depending on the current used software. In my upcoming research I would like to establish a readable communication path between some gcode readers and 3d printers. Therefore I have already adjusted my code for exporting finished data files as well as textboxes for inputing new data. The only struggle that I am currently dealing is the fact, that I am not familiar with the matlab cell editing operations which lead me to your much more refined approach regarding this matter.

Risposta accettata

Jan
Jan il 4 Mar 2021
Modificato: Jan il 4 Mar 2021
I do not undestand why "Text Nr.1" appears multiple times. If this is a typo only:
In = {your cell};
Out = cell(size(In));
for k = 1:numel(In)
if ischar(In{k});
Out{k} = {In{k}, [], []}; % Or '' instead of [] ?
else
Out{k} = num2cell(In{k});
end
end
Result = cat(1, Out{:});
If you provide a tiny set of input data, I could test my code.
  6 Commenti
Jan
Jan il 5 Mar 2021
Modificato: Jan il 6 Mar 2021
I do not understand, why you do not mention, how the result of my posted code differs from your expectations.
You have posted some example data in the DATA.mat file. There I find a cell with this contents:
72×1 cell array
{'StartCurve' }
{1268×3 double}
{'EndCurve' }
{'StartCurve' }
{1268×3 double}
{'EndCurve' }
{'StartCurve' }
{1268×3 double}
{'EndCurve' }
{'StartCurve' }
{1268×3 double}
{'EndCurve' }
...
The double values are 1268×3 double matrices and I guess, that you mean this by "*nested 2345x3 double". I do not see anything "nested" here.
The code contains 48 char vectors 'StartCurve' and 'EndCurve'. I guess this is what you call "Text 1" and "Text 2".
The other 24 cell elements are 1268 x 3 vectors.
My code joins these data to a 30'480 x 3 cell matrix: 48 text rows and 24 * 1268 numerical rows.
Result = {'StartCurve', [], []; ...
-75, -4.8308, 5; ...
... 1267 further rows
'EndCurve', [], []; ...
'StartCurve', [], []; ...
-38, -4.8308, 5; ...
... 1267 further rows
'EndCurve', [], []; ...
... and so on
}
As far as I can see, I've posted a working code yesterday. Please take the time to try it and to explain, what changes you need.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by