put together cells from different cell arrays and writing it to a file

1 view (last 30 days)
Hey I have got multiple patch objectes that have data in the UserData property. I attached two mat-files to show how these UserData cell arrays will look like.
Starting from cell(1,3) I want to put togehter the cells that posess the same position in one new variable. After that I want to write the joint data into a file with fopen() and fprintf() in the right order.
What data type do you recommend to use knowing I want to write it into a file afterwards?
And have you an idea how to handle the empty cells and the different sizes of the cell arrays? E.g. UserData_1 has data in cell(1,5) and UserData_2 hasn't. Is there a function that tells you if a certain position in a cell array exists? Please note that it should also work with more than two cell arrays that have different numbers off cells.
The file with the Data from the cell arrays is supposed to look like this:
M103
M103
M103
M103
M103
M103
M103
G00 X0 Y0
G00 X0 Y0
G00 X0 Y0
G00 X0 Y0
G00 X0 Y0
G00 X0 Y0
Q1=30 F0
Q1=30 F0
Q1=30 F0
Q1=30 F0
Q1=30 F0
Q1=30 F0
Q1=30 F0
Q1=30 F0
G01 X0 Y0 F0
G01 X0 Y0 F0
G01 X0 Y0 F0
G01 X0 Y0 F0
G01 X0 Y0 F0
G01 X0 Y0 F0
I'm looking forward hearing from you. I'm currios what solution you propose.
Best
Tim

Answers (1)

Tim Felix Liesching
Tim Felix Liesching on 12 Mar 2021
This was my first idea to join all the cells to one. I have an array with the handles of all my patch objects, then I determine the largest cell and run two for-loops. To make sure that a certain cell is not empty or has an entry at all I check if length(currentPatch) >= j and if iscell(currentPatch{j]). This cell now needs to be written into a file with fopen and fprintf() either with whitespace/ empty row between the "text blocks" (like I have shown in my question) or at once. I dont know how to put whitepace between these blocks
l = []
exportCell = {}
for i = 1:length(patch_array)
l = [l,length(patch_array(i).UserData)]
end
lmax = max(l)
for j = 3:lmax
for k = 1:length(patch_array)
currentPatch = app.patch_array(k).UserData
if length(currentPatch) >= j && iscell(currentPatch{j})
exportCell = [exportCell; currentPatch{j}]
end
end
end

Community Treasure Hunt

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

Start Hunting!