Take values from an matrix automatically.
    조회 수: 6 (최근 30일)
  
       이전 댓글 표시
    
Hi !!!, Good morning.
I would like to help me in the following:
I have an 18 X 3 matriaz, which can also be 18 X n
Each element of a line is a variable
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc; clear; close all; format short
Prog=[1.19  1.89  2.74  3.53  4.43  1.76  0.22  4.20  2.39  3.97  3.24  4.43  0.96  6.41  2.00  7.07  3.34  6.77  
  0.56  1.41  2.27  3.23  4.18  1.36  0.96  4.05  1.64  3.66  3.61  3.67  0.53  7.02  2.02  6.30  3.77  6.92  
  1.13  2.16  2.73  3.87  5.08  1.49  0.46  3.80  1.65  4.13  3.62  4.09  0.69  6.86  2.14  6.30  3.31  7.03 ];
% To get each of the elements in a variable I do the following for the first line.
dx1=Prog(1,1);
dy1=Prog(1,2);
dx2=Prog(1,3);
dy12=Prog(1,4);
dx3=Prog(1,5);
dy13=Prog(1,6);
dx12=Prog(1,7);
dy2=Prog(1,7);
dx21=Prog(1,7);
dy21=Prog(1,10);
dx31=Prog(1,11);
dy22=Prog(1,12);
dx13=Prog(1,13);
dy3=Prog(1,14);
dx22=Prog(1,15);
dy31=Prog(1,16);
dx32=Prog(1,17);
dy32=Prog(1,18);
% With this I have each of the values of the first line.
% How do I automatically get the code to take the values of the following lines?
댓글 수: 5
  Walter Roberson
      
      
 2019년 9월 10일
				If you need to take a copy of the current values to use in calculations while you change the array, then you can
saved_row = Prog(i,:);
and then saved_row(6) would be dy13 and so on without having to write each value to a variable individually.
답변 (1개)
  Fabio Freschi
      
 2019년 9월 10일
        Prog_old = Prog;
% modify Prog as desired
Prog = Prog*2; % dummy operation
% reload the old version
Prog = Prog_old;
참고 항목
카테고리
				Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!