Data representation in a specific format

1 回表示 (過去 30 日間)
Saugata Bose
Saugata Bose 2019 年 4 月 28 日
コメント済み: Walter Roberson 2019 年 4 月 29 日
Hi
I am working on a large data set which I need to convert in a specific format for further processing. I am looking for your advice in this regard.
Sample data
A=[0.99 -0.99
1 -1
0.55 -0.55]
Sample output:
val(:,:,1,1)=0.99
val(:,:,2,1)=-0.99
val(:,:,1,2)=1
val(:,:,2,2)=-1
val(:,:,1,3)=0.55
val(:,:,2,3)=-0.55
During working on this, I found a code inside a cnn toolbox of matlab r2018b
function dummifiedOut = dummify(categoricalIn)
% iDummify Convert a categorical input into a dummified output.
%
% dummifiedOut(1,1,i,j)=1 if observation j is in class i, and zero
% otherwise. Therefore, dummifiedOut will be of size [1, 1, K, N],
% where K is the number of categories and N is the number of
% observation in categoricalIn.
% Copyright 2015-2016 The MathWorks, Inc.
numObservations = numel(categoricalIn);
numCategories = numel(categories(categoricalIn));
dummifiedSize = [1, 1, numCategories, numObservations];
dummifiedOut = zeros(dummifiedSize);
categoricalIn = iMakeHorizontal( categoricalIn );
idx = sub2ind(dummifiedSize(3:4), int32(categoricalIn), 1:numObservations);
dummifiedOut(idx) = 1;
end
function vec = iMakeHorizontal( vec )
vec = reshape( vec, 1, numel( vec ) );
end
Can we modify this block of code in such a way to produce the sample output?
I am looking for your advice.
thanks,
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 4 月 28 日
You write to the same location multiple times.
Are your two values always exact negatives of each other?
Saugata Bose
Saugata Bose 2019 年 4 月 28 日
walter hi
most of the time, data appears exact opposite of the first one.
thanks,

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 4 月 28 日
val = repmat(permute(A, [4 3 2 1]), num_rows, num_cols, 1, 1);
where num_rows is the number of rows you want for val(:,:,1,1) and num_cols is the number of columns you want for val(:,:,1,1)
  2 件のコメント
Saugata Bose
Saugata Bose 2019 年 4 月 29 日
@Walter Roberson
thanks for ur suggestion. Though I understand how this code block works yet, I need to understand if I am looking for such a following output, what changes the code block may demand? Could you please highlight this issue?
Sample output:
val(:,:,1,1)=0.99
val(:,:,2,1)=-0.99
val(:,:,3,1)=0
val(:,:,4,1)=0
val(:,:,1,2)=1
val(:,:,2,2)=-1
val(:,:,3,2)=0
val(:,:,4,2)=0
val(:,:,1,3)=0.55
val(:,:,2,3)=-0.55
val(:,:,3,3)=0
val(:,:,4,3)=0
Walter Roberson
Walter Roberson 2019 年 4 月 29 日
A = [0.99 -0.99 0 0
1 -1 0 0
0.55 -0.55 0 0
]
together with the code I posted.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by