Adding values in a matrice?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Stephen23
el 19 de En. de 2017
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!
Respuestas (1)
Adam
el 19 de En. de 2017
Editada: Adam
el 19 de En. de 2017
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!
0 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!