Converting a 2d vector to a 4d vector

31 views (last 30 days)
Basu Sau
Basu Sau on 25 Feb 2019
Commented: Basu Sau on 25 Feb 2019
In a machine learning task, I need a 4d single type data to fed for training. But my data is in a 2d format. Would you please show me how to do this conversion.
Input:
for data of 28th row,
val(28,1)=1.5
val(28,2)=2.7
output:
val(:,:,1,28)=1.5
val(:,:,2,28)=2.7
I m looking for your advice in this regard.
Thanks,

Accepted Answer

ANKUR KUMAR
ANKUR KUMAR on 25 Feb 2019
Let's take a random data A
A=randi(10,30,2);
Use permute to change into 4D
B=permute(A,[3,4,2,1]);
Now, B(:,:,2,24) and A(24,2) are same.
>> B(:,:,2,24)==A(24,2)
ans =
logical
1
  3 Comments
Basu Sau
Basu Sau on 25 Feb 2019
thanks ankur for a such explainatory comment

Sign in to comment.

More Answers (1)

madhan ravi
madhan ravi on 25 Feb 2019
Aternatively:
[m,n]=size(val);
Val=reshape(val.',1,1,n,m)

Community Treasure Hunt

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

Start Hunting!