How to duplicate rows while skipping/excluding specific rows?

조회 수: 5 (최근 30일)
Jayne
Jayne 2021년 5월 26일
댓글: Jayne 2021년 6월 1일
What I have:
I have a cell array:
That second column is the data that is nested into the first column.
What I need:
I need each number (that is not 1000) duplicated. These numbers correspond to data in another matrix, so the Indicies MUST match. I'm at a loss.
My current attempt:
The final matrix PRN should be the same size as A (so the indexes match). It is missing 1173 rows of data. My current theory is that there are other blank lines in the data that (for god knows what reason) don't need to be deleted.
This is a piece of a function that is trying to parse data from many many files. So I hope I gave you enough information to work off of.
Thanks for any help, ideas or refrence materials that you might send my way.

채택된 답변

Jan
Jan 2021년 5월 26일
편집: Jan 2021년 5월 26일
C = str2double(A(~cellfun('isempty', A)));
idx = repmat(1:numel(A), 2, 1);
idx(2, C == 1000) = 0;
PRN = C(idx(idx ~= 0));
  댓글 수: 1
Jayne
Jayne 2021년 6월 1일
Thank you for your answer. That does double it and is very efficient. I still have rows missing, but I think the problem is in my data/assumptions, not your code.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by