필터 지우기
필터 지우기

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에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by