MATLAB Answers

Translated by

이 페이지의 내용은 영어에서 자동 번역되었습니다. 자동 번역 기능을 해제하려면 "<a class="turn_off_mt" href="#">여기</a>"를 클릭하십시오.

Writing first and last line of each cell

Latest activity Edited by madhan ravi
on 7 Apr 2019
Accepted Answer by dpb
Dear, I have a question about write file.
I have a file xxMM. It is a 19x1 cell.
The first cell has 14x6 double. The second cell has 12x6 double. The third 9x6 double. The fourth 6x6 double and etc.
I would like write a file (double) with only the last line of each cell. Only of first cell (14x6) I would like write the first and of last line of cell. All the others I would like to write only the last line
For example, the file is xx.
I would like that xx be a double and that the first line be the first and the last line and the six columns of first file (cell) of xxMM.
The second line of xx be only the last line and the six columns of second file (cell) of xxMM.
The third line of xx be only the last line and the six columns of third file (cell) of xxMM and etc.
I did it:
for i=1:length(xxMM)
But, the form I just write the last line of each cell. But the first cell I would like of first and the last line.
How can I do it ?
Thank you advanced


Sign in to comment.

1 Answers

Answer by dpb
on 7 Apr 2019
Edited by dpb
on 7 Apr 2019
 Accepted Answer

Just have to handle the special case outside the loop...
for i=1:length(xxMM)
or, you could dispense with the explicit for...end loop with cellfun
xx=[xxMM{1}(1,:);cell2mat(cellfun(@(x) x(end,:),xxMM,'uni',0))];


[Answer moved to comment --dpb]
Thank you very much. It works !
The first code show me a erro. But the second works \o/
I did a test here on sample; code worked just the actual code and error message. Maybe you missed "the curlies" to dereference the cell???
% ^^^^^----- was missing at the beginning

Sign in to comment.

Translated by