필터 지우기
필터 지우기

Using the "For" loop with imported data?

조회 수: 1 (최근 30일)
Miranda Moore
Miranda Moore 2016년 11월 29일
댓글: Miranda Moore 2016년 11월 29일
I am using data from an excel spreadsheet to create a for loop that does multiple commands with the given data- such as adding the first ten elements from each column. However, when using the for loop, I keep ending up with an error.
Where each column is labelled x1-x10, and I want to add the first element of each to get the total. For this example, it is row 3. However, I need to add the first element of the ten columns for every single row value, which there are 55 of. This code is not only showing an error but is ineffective for what I am trying to do. Please don't "do it for me", but any help in explaining how to go about this problem and errors in my code would be appreciated.
Thanks
function summertravel
miles = x1(n,1)+x2(n,1)+x3(n,1)+x4(n,1)+x5(n,1)+x6(n,1)+x7(n,1)+x8(n,1)+x9(n,1)+x10(n,1);
for m = miles
if n==3
fprintf('total miles %d', miles)
end

답변 (1개)

KSSV
KSSV 2016년 11월 29일
When you read the data of excel using:
num = xlsread('youfile.xlsx');
num will be a matrix, and matrix indexing is easy. https://in.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html.Resd the matrix indexing and solve the problem.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by