MATLAB Answers

How to scan through a cell array with mixed data types based on a specific index condition and changeable row size?

19 views (last 30 days)
David Mrozek
David Mrozek on 9 Mar 2021
Commented: David Mrozek on 9 Mar 2021
Hello everyone,
In the attachment you will see a cell array with text and value as well as intended empty spaces shown as brackets [].
I wanted to achieve the following task, but I am unable to properly excute or write a decent code:
1.) In the first step I want to extract each row index from the attachment right before the string 'EndCurve' and brackets [] appear (Condition 1 for the indexing process):
Fig.1 Example Cutout of the provided data set
As seen above in the above cutout, the index that I would like to get here in the cutout is 189. The following index contains a string as well as a brackets hence it does not meet my index condition. The above cutout is just a small part of the data. However I want to get the all the indices which meet that condition mentioned in point 1.).
A.)In order the solve this I got the following idea:
b.) Get all the indices from each block (value range of the numerical data until the 'EndCurves' as string data type )
c.) Substract the last index with 1 in order to get the desired index value
D.) Problem:
I am unable to "scan" the the mentioned blocks since the rows of each block are not consistent.
Therefore I would like to ask you, if there is a "simple" way to write such a code which...
"scans" through the rows,
performs the the ideas mentioned in point c.) and d.)
I would really appreciate it if you could contribute to this solution!!! Or even come up with a better approach. If you could, mention your thought process from start to finish since this method helped me a lot with other tasks, please. I also wanted to thank everyone for the previous answers and patience with my demands.
Notice & Background informations (In case anyone asked me about the purpose):
I am currently dealing with a project that evaluates the communication between 3D printer, MatLab and Excel. Therefore I am currently writing a MatLab Subroutine in order to run it as a "communication tool". I am currently at the final stage of this project. The probably biggest obstacle is now the fact, that I need to secure a communication for the 3D printers. This leads me to the solution of writing a macro with the suitable 3D printer execution language. My questions originates from the problem that all printer need a different amount of rows in order to initiate the "start printing" command. So if I would knew the index, i could set up a "border" for my macro which separates the numeric values as well as the string data types.
So if you could help me with my little problem I would be able to "tell" each of 3D printers which row is responsible for the "starting command"

Accepted Answer

Jan on 9 Mar 2021
In the first step I want to extract each row index from the attachment right before the string 'EndCurve'
% Assuming that your cell array is called C:
index = find(strcmp(C(:, 1), 'EndCurve')) - 1

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by