How to place values in given column indexes?

2 ビュー (過去 30 日間)
lucksBi
lucksBi 2018 年 1 月 16 日
コメント済み: lucksBi 2018 年 1 月 16 日
Hi all I have two cell arrays:
array1 = {[1,4,7,8];[1,2,3,5,6,7,9]}
array2 = {[3;5;6;8],[4;6],[3;5;6;8],5,[],[],[];[1;3;5;6],[2;4],[2;5;7],[3;5],[2;4],[1;3;5;6],[2;4;7]}
Elements of array1 corresponds to elements of array2. i want to store elements of array2 in order given by array1. Like [3;5;6;8] at row1 col1, [4;6] at row1 col4, [3;5;6;8] at row1 col7 and 5 at row 1 col8. elements in between can be filled with NaN or empty braces.
Same for [1,2,3,5,6,7,9], (all elements will be stored at col indexes goven by array1 but at row2.)
result = {[3;5;6;8],[],[],[4;6],[],[],[3;5;6;8],5,[];[1;3;5;6],[2;4],[2;5;7],[],[3;5],[2;4],[1;3;5;6],[],[2;4;7]}
kindly help.
  2 件のコメント
Birdman
Birdman 2018 年 1 月 16 日
What you want is not clear to me.
lucksBi
lucksBi 2018 年 1 月 16 日
@Roberson has given accurate answer for this. Thank You for your time.

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 1 月 16 日
for k = 1 : size(array1, 1)
result(k, array1{k}) = array2(k);
end
Vectorizing this further is not worth the effort.
  1 件のコメント
lucksBi
lucksBi 2018 年 1 月 16 日
Thanks alot.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by