How to append data inbetween the Array without overwriting its original data ?

2 ビュー (過去 30 日間)
pooja
pooja 2014 年 3 月 15 日
コメント済み: pooja 2014 年 3 月 20 日
Hello,
i am a beginner in matlab ,Sorry if i ask something stupid , but i really need help
i have a array named " train_data " of size 67x103 (having 67 instances and 103 features)
i want to add "two" corrosponding rows to each 67 rows of train_data
for example:
row-1 -->0.45 0.34 0.38 .....
row-2 has to be added as:
row-2 --> log(0.45) log(0.34) log(0.38) ......
row-3 has to be added as:
row-3 --> exp(0.45) exp(0.34) exp(0.38) ......
is it possible to do such thing in "train_data" array without overwriting it ??
Please Help , i tried my best to make my question clear , i am hoping for the answer
Thank You for Consideration !!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 3 月 15 日
[n,m]=size(A)
B=permute(reshape([A;log(A);exp(A)]',m,n,3),[2 1 3])
out=reshape(B(:,:)',m,[])'
  2 件のコメント
pooja
pooja 2014 年 3 月 15 日
編集済み: pooja 2014 年 3 月 15 日
Thank you Soooo Much...You saved My life Sir
i exactly needed this code
Now i am trying to understand it :P
pooja
pooja 2014 年 3 月 20 日
hello sir sorry agan
i have 14 class x 67 labels in target
problem : 1st column as it is ,add 2nd and 3rd column having same value as 1st column , reulting dimensions shold be 14 x 201
i tried so many combinations on your given code like
[q,p]=size(train_target);
Y=permute(reshape([train_target;train_target;train_target]',q,p,3),[2 1 3]);
train_target=reshape(Y(:,:)',q,[])';
train_target=transpose(train_target);
but all are disaster .... can you help again please ?

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

その他の回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 3 月 15 日
編集済み: Mischa Kim 2014 年 3 月 15 日
Pooja, check out INSERTROWS (description in Jiro's blog) in the File Exchange. If you need to add rows at the top or bottom of an array you can simply use:
C = [A; B]
where you add A on top or B on the bottom of the other array.

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by