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 CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by