Info
此问题已关闭。 请重新打开它进行编辑或回答。
How can I use different elements that are in a matrix, while they are read in a 'for' loop?
    1 次查看(过去 30 天)
  
       显示 更早的评论
    
Good morning,
I have to work with data that it's imported from an Excel document. This data takes form as a matrix [4x2], however I need to keep adding data to the Excel so it might be a matrix [4x3], [4x4] , etc. After introducing all the data, I have to work with each column individually, because each row means different things. For that reason, I would like to know if there is any kind of 'for' loop that reads all the colums individually that will form the matrix and let me , for example, use the first and second element of each column to calculate a sum.
Another thing that it might work is split the matrix by columns and work just with the rows but I read on another questions that its a bad idea --' Apologizes in advance for my poor Matlab programming skills and my English,
Thank you for your help,
Best regards
0 个评论
回答(1 个)
  KSSV
      
      
 2017-9-4
        
      编辑:KSSV
      
      
 2017-9-4
  
      A = rand(4,3) ;   % A random matrix
B1 = A(1,:)    % Extracts entire first row 
B2 = A(:,1)   % Extracts entire first column 
B3 = A(2,3)   % Extracts 2nd row, 3rd column element
Extracting the rows, columns and elements you want is very easy. Read about MATLAB matrix indexing.  https://in.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!