필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
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"

채택된 답변

Jan
Jan 2021년 3월 9일
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
  댓글 수: 3
Stephen23
Stephen23 2021년 3월 9일
편집: Stephen23 2021년 3월 9일
a) No. strcmp does not "convert" any data. Based on tests I performed recently for another project, strcmp ignores all data types that are not string or char (possibly in a cell array)**. strcmp does not "execute" anything: there are no function handles or executable code involved as arguments to strcmp. The length (i.e. number of characters) is only relevant because a different number of characters means that the two inputs clearly do not match (presumably strcmp does this trivial check early in its processing).
b) Probably. Did you try it?
** as far as I can tell, this behavior is undocumented. Even numeric values are ignored, not even considered as character codes:
+'a'
ans = 97
strcmp(97,'a')
ans = logical
0
David Mrozek
David Mrozek 2021년 3월 9일
Yes, works perfectly. Thank you again for the brief and enriching insight!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by