Very tricky:Manipulation with complex array
1 回表示 (過去 30 日間)
古いコメントを表示
I need to write a m.file function for this.
For example
array X = [4, 1, 1, 3, 8, 12], I need to make the array which will contain bold ones as well Y = [4, 1, 5, 1, 3, 4, 8, 12, 20].
3 件のコメント
採用された回答
Fabio Freschi
2022 年 9 月 19 日
編集済み: Fabio Freschi
2022 年 9 月 19 日
% original vector
X = [4, 1, 1, 3, 8, 12];
% reshape to have 2xN vector
W = reshape(X,2,[]);
% calculate the sum
S = sum(W,1);
% concat the vector and reshape
Y = reshape([W; S],1,[])
3 件のコメント
Fabio Freschi
2022 年 9 月 19 日
Why using for loops when the vectorized version is effective, cleaner and more efficient?
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!