Converting a 2d vector to a 4d vector

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,

 Akzeptierte Antwort

ANKUR KUMAR
ANKUR KUMAR am 25 Feb. 2019

0 Stimmen

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 Kommentare

Basu Sau
Basu Sau am 25 Feb. 2019
hi Ankur. would u pls explain the parameters u pass inside permute()?
ANKUR KUMAR
ANKUR KUMAR am 25 Feb. 2019
Bearbeitet: ANKUR KUMAR am 25 Feb. 2019
First input of permute is the data itself.
Second input is in the row matrix which contains the sequence of dimension you wish to put it.
For example, in B, we have stored first the fourth dimension, then the thrid dimension, followed by second and first.
If we write,
B=permute(A,[3,4,1,2]);
then
>> B(:,:,24,2)==A(24,2)
ans =
logical
1
SIMPLE EXAMPLE
>> A=magic(5)
A =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> permute (A,[2,1])
ans =
17 23 4 10 11
24 5 6 12 18
1 7 13 19 25
8 14 20 21 2
15 16 22 3 9
Permute simply changes the dimension as per your input in purmute command.
Basu Sau
Basu Sau am 25 Feb. 2019
thanks ankur for a such explainatory comment

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

madhan ravi
madhan ravi am 25 Feb. 2019

1 Stimme

Aternatively:
[m,n]=size(val);
Val=reshape(val.',1,1,n,m)

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 25 Feb. 2019

Kommentiert:

am 25 Feb. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by