フィルターのクリア

different dimension matrix addition

9 ビュー (過去 30 日間)
PetronasAMG
PetronasAMG 2018 年 2 月 18 日
コメント済み: Guillaume 2018 年 2 月 18 日
for example,
A = [1 2 3 4 5]
B = [0 0 0 0 0 6 7 8 9 10]
and i need C = [1 2 3 4 5 6 7 8 9 10]
is there a way to make this possible? I know that in math different dimension matrix addition is impossible.first i did i=1:length(x). But right now I used if loop to run the first values to get matrix A and then when iteration reaches 5 then the first condition ends (1<x(i)<5), then I used another if condition (5<x(i)<10) it calculates the matrix B. this is the reason why first 5 values of B are zeros because x(i) is an iteration. Please help me combine these two matrix so i can get C matrix as my answer

採用された回答

Star Strider
Star Strider 2018 年 2 月 18 日
I am not certain what your constraints are.
One (rather obvious) way to get ‘C’ is:
A = [1 2 3 4 5];
B = [0 0 0 0 0 6 7 8 9 10];
C = [A B(numel(A)+1 : end)];
  1 件のコメント
Guillaume
Guillaume 2018 年 2 月 18 日
Another option:
A(numel(B)) = 0; %expand A to be the same size as B
C = A+B

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

その他の回答 (0 件)

カテゴリ

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