Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

How can I use different elements that are in a matrix, while they are read in a 'for' loop?

1 view (last 30 days)
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

Answers (1)

KSSV
KSSV on 4 Sep 2017
Edited: KSSV on 4 Sep 2017
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

This question is closed.

Community Treasure Hunt

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

Start Hunting!