How to add a more element in an existing cell array in specific positions?

14 ビュー (過去 30 日間)
Ujwal
Ujwal 2015 年 11 月 10 日
コメント済み: Ujwal 2015 年 11 月 10 日
Hi, The problems starts like this.
I have a cell array named: FlowRate = cell(1,16);
Initially,
Flow =
[498,1] [398,3] [343,1] [840,3] [899,2] [792,2] [828,4] [440,2] [812,5] [395,4][495,5] [792,1] [876,5] [563,5] [629,1] [280,3]
After some calculation I get an array: l =[3 4 10 16], I have to make add this value [490,1] to cell position mentioned in 'l'.
So, the solution should be:
New_Flow =
[498,1] [398,3] [343,1;490,1] [840,3;490,1] [899,2] [792,2] [828,4] [440,2] [812,5] [395,4;490,1][495,5] [792,1] [876,5] [563,5] [629,1] [280,3;490,1]
I would be grateful to get your support. Than You.

採用された回答

Stephen23
Stephen23 2015 年 11 月 10 日
編集済み: Stephen23 2015 年 11 月 10 日
Note that l is not a good variable name, as it is too easy to confuse for other characters.
Try this:
>> C = {[498,1],[398,3],[343,1],[840,3],[899,2],[792,2],[828,4],[440,2],[812,5],[395,4],[495,5],[792,1],[876,5],[563,5],[629,1],[280,3]};
>> idx = [3,4,10,16];
>> new = [490,1];
>> C(idx) = cellfun(@(v)[v;new],C(idx),'UniformOutput',false);
>> C{:}
ans =
498 1
ans =
398 3
ans =
343 1
490 1
ans =
840 3
490 1
ans =
899 2
ans =
792 2
ans =
828 4
... etc
  1 件のコメント
Ujwal
Ujwal 2015 年 11 月 10 日
thank you very much for your quick response.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 11 月 10 日
what_to_add = [490,1];
for K = I
New_Flow{K} = [New_Flow{K}, what_to_add];
end
  1 件のコメント
Ujwal
Ujwal 2015 年 11 月 10 日
absolutely very short answer. I am sorry for not knowing this simple text too.

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

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by