필터 지우기
필터 지우기

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

답변 (1개)

KSSV
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

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by