Borrar filtros
Borrar filtros

Using the "For" loop with imported data?

1 visualización (últimos 30 días)
Miranda Moore
Miranda Moore el 29 de Nov. de 2016
Comentada: Miranda Moore el 29 de Nov. de 2016
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

Respuestas (1)

KSSV
KSSV el 29 de Nov. de 2016
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.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by