Using the "For" loop with imported data?

1 次查看(过去 30 天)
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