Effacer les filtres
Effacer les filtres

Using the "For" loop with imported data?

1 vue (au cours des 30 derniers jours)
Miranda Moore
Miranda Moore le 29 Nov 2016
Commenté : Miranda Moore le 29 Nov 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

Réponses (1)

KSSV
KSSV le 29 Nov 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.
  1 commentaire
Miranda Moore
Miranda Moore le 29 Nov 2016
Thank you so much!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by