David Mrozek asked . 2021-10-08
How to deal with nested arrays where the columns and rows are in different dimensions?
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.
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.
cell array , unnest , double
John Michell answered . 2024-12-21 15:42:26
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.
Not satisfied with the answer ?? ASK NOW