Adding values in a matrice?

1 回表示 (過去 30 日間)
Philipp Mueller
Philipp Mueller 2017 年 1 月 19 日
コメント済み: Stephen23 2017 年 1 月 19 日
Hi,
How can i add values (new row -> vector row) at this 6*4 double matrice ? Ok this question sounds stupid....
My matrice:
Plot_Positions = [ 3, 21, 7, 7;
12, 21, 7, 7;
3, 12, 7, 7;
12, 12, 7, 7;
3, 3, 7, 7;
12, 3, 7, 7];
Now i want to add this vectors.. How does it work?
Plot_Position_one= [ 83, 21, 7, 87]
Plot_Position_two= [ 3, 21, 57, 57]
Plot_Position_three= [ 33, 321, 37, 7]
Plot_Position_four= [ 3, 21, 27, 27]
Plot_Position_five= [ 53, 21, 47, 72]
Plot_Position_six= [ 3, 21, 27, 87]
Is this possible like this + a for loop? It should work dynamically...
Plot_Positions = cell(1, 6); %???
Plot_Positions{1}= [ 3, 21, 7, 7]
Plot_Positions{2}= [ 12, 21, 7, 7]
Plot_Positions{3}= [3, 12, 7, 7]
Plot_Positions{4}= [12, 12, 7, 7]
Plot_Positions{5}= [ 3, 3, 7, 7]
Plot_Positions{6}= [ 12, 3, 7, 7]
  1 件のコメント
Stephen23
Stephen23 2017 年 1 月 19 日
Creating lots of numbered variables and then trying to process them in a loop is a really bad idea:
As Adam already said: keep all your data in one variable and your code will be simpler, faster, and much more robust. Remember to use the dimensions of ND arrays!

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

回答 (1 件)

Adam
Adam 2017 年 1 月 19 日
編集済み: Adam 2017 年 1 月 19 日
If you just define your values you want to add in a single 6*4 matrix instead of creating 6 un-necessary variables you can just add them together like any two matrices of equal size.
Don't use cell arrays when you don't need to and don't create lots of numbered variables when you don't need to. It just complicates code. Adding numeric matrices is about the simplest operation in Matlab and it works perfectly if you define the things to add correctly!

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by