Hi,
I struck into a phase where my data came into one format and I need to reshape it to other format. I have tried reshape and permute, yet, I did not achieve the ultimate result. Would you please help me to get the result. And I would really appreciate if you would please explain your solution.
Input:
A={5 x 1} cell type data where every cell is in this format {300 x 18 single}
Expected Output:
I expect to have an output where each element of A will be formatted as 18 x 300 x 1 x 1 structure.
I have tried to implement the following code to format A but I did not achieve the expected result.
z = cellfun(@(X) permute(X,[3 2 1]),A,'UniformOutput',false);
I am looking for your advice in this regard.
Thanks

댓글 수: 3

madhan ravi
madhan ravi 2019년 6월 26일
Bose I would expect a 300 X 18 X 1 X 5 matrix , please illustrate.
Saugata Bose
Saugata Bose 2019년 6월 26일
@madhan: Hi. I would expect each cell from A(of size 300 x 18) will turn into a 18 x 300 x 1 x 1, 18 x 300 x 1 x 2, 18 x 300 x 1 x 3, 18 x 300 x 1 x 4 and 18 x 300 x 1 x 5 format. I am not sure though, whether it is possible or not. what you think?
per isakson
per isakson 2019년 6월 26일
What's the meaning of the colons in A(1,:1,:1,:1) ?

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

 채택된 답변

madhan ravi
madhan ravi 2019년 6월 26일

0 개 추천

Try this:
AA=cellfun(@(x) x.',A,'un',0);
Wanted = cat(4,AA{:})

댓글 수: 3

@Madhan. thank you very much for your solution. But I expect the output would be like this:
A(1,:1,:1,:1)=0.5,
A(1,:2,:1,:1)=0.7
....
A(1,:300,:1,:1)=0.8
...
A(18,:300,:1,:1)=0.99.
...
...
...
A(18,:300,:1,:5)=0.89, (here, the values are considered at random
But the solutions does not appear like this. May be it was my mistake not elaborating the idea properly. What kind of change does this code require then?(For you and others I edit the question with the expected outputs)
thanks,
madhan ravi
madhan ravi 2019년 6월 26일
편집: madhan ravi 2019년 6월 26일
Bose keep the facts straight the latter comment you made seems to contradict the original question before you edited.
:1 is not a valid MATLAB syntax
Saugata Bose
Saugata Bose 2019년 6월 26일
@Madhan. I absolutely agree. this is my wrong understanding. So to access each of the 4 d element seperately I need to acces by A(:,:,:,1). Thanks for such a solution. I'll edit my post to undo my wrong output expectation.

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

추가 답변 (1개)

KSSV
KSSV 2019년 6월 26일

0 개 추천

% CReate random input for demo
A = cell(5,1) ;
for i = 1:5
A{i} = rand(300,18) ;
end
B = zeros(18,300,5) ;
for i = 1:5
B(:,:,i) = A{i}' ;
end

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2019년 6월 25일

편집:

2019년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by