Hi, I have the following loop which I would like to vectorise: Here C is an array of integers, M is a cell of integer arrays.
For example : for one case M is a 1x8 cell, with contents =
M = {1, 2, [3,4,7,9,10], [5,6,8,11,12], [13,14,17,19,20], [15,16,18,21,22], 23, 24}
for i=1:length(data)
j= C(i);
n = M{j};
end
I was thinking of a solution like n = M{C}, however that didnt workout. Neither did n = M{C(:)}. Can someone help in vectorising this loop ?
Thanks

2 件のコメント

Stephen23
Stephen23 2017 年 11 月 28 日
編集済み: Stephen23 2017 年 11 月 28 日
@Balkrishna Patankar: can you please explain what you want to achieve? What is the expected output?
Balkrishna Patankar
Balkrishna Patankar 2017 年 11 月 28 日
Expected output: For the case of
C=[ 1;2;3;3;4;4;3;4;3;3;4;4;5;5;6;6;5;6;5;5;6;6;7;8]
M is a 1x8 cell with M ={ 1 ,2 ,[3,4,7,9,10] [5,6,8,11,12] [13,14,17,19,20], [15,16,18,21,22] ,23 ,24}
The output should be something like:
1 2 [3,4,7,9,10] [3,4,7,9,10] [5,6,8,11,12] [5,6,8,11,12] [3,4,7,9,10] [5,6,8,11,12] [3,4,7,9,10] [3,4,7,9,10] [5,6,8,11,12] [5,6,8,11,12] [13,14,17,19,20] [13,14,17,19,20] [15,16,18,21,22] [15,16,18,21,22] [13,14,17,19,20] [15,16,18,21,22] [13,14,17,19,20] [13,14,17,19,20] [15,16,18,21,22] [15,16,18,21,22] 23 24

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

 採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 28 日

0 投票

M(C)
to get the result in cell form. If you want a row vector of all of the values concatenated together then
[M{C}]

1 件のコメント

Balkrishna Patankar
Balkrishna Patankar 2017 年 11 月 28 日
Thank you for your answer.

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

その他の回答 (0 件)

カテゴリ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by