How can I change from Cell to Double and writing in many lines

조회 수: 1 (최근 30일)
Dear, I would like solve a problem about transformation and save in the file
I have a file A that is 19x1 cell. And in each cell I have a matrix 6x6. for example A(1,1) = 6x6 Double, A(2,1) = 6x6 Double ...A(19,1) = 6x6 Double.
I would like write the file A in Double and each matrix stay in one line with 36 column and write (save) these data in the archive.
For example:
From A(1,1) = 6x6 Double to A(1,36)
From A(2,1) = 6x6 Double to A(2,36)
From A(3,1) = 6x6 Double to A(3,36)
.
.
From A(19,1) = 6x6 Double to A(19,36)

채택된 답변

Rik
Rik 2019년 4월 5일
The code below should do what you want.
%generate input
A=cellfun(@(x) {x+rand(6,6)},num2cell(1:19)');
%convert the cell contents to row vectors
B=cellfun(@(x) reshape(x,1,[]),A,'UniformOutput',false);
%concatenate into a single double array
C=cell2mat(B);
  댓글 수: 4
Leonardo Barbosa Torres dos Santos
Thank you very much. It works.
I changed many things but it I didn't not.
Now it is working \o/
Let me do more one question, please.
Is possible I write these lines starting in column 7 ?
For example:
The program is writing:
Line 1 and Column 1 until 36
Line 2 and Column 1 until 36
.
.
Line 19 and colund 1 until 36.
I would like write starting in column 7 until 42.
line 1 and Column 7 until 42
line 2 and Column 7 until 42
.
.
line 19 and Column 7 until 42.
Is it possible ?
thank you
Rik
Rik 2019년 4월 6일
Rewrite the anonymous function inside the cellfun to suit your needs.
Also, if my answer solved your problem, please consider marking it as accepted answer.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by