- replace 0:size(dataN) by 1:size(dataN,2). Matlab's indexing is one-based.
- avg = mean(val); overwrites avg in every iteration; only the last value will persist
- "trying to extract the first row of the array (dataN)" dataN(:,k) refers to the k:th column
Getting error about index in for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
%for loop for plotting given data
for k = 0:size(dataN)
val = dataN(:,k);
avg = mean(val);
end
I am getting this error:
Index in position 2 is invalid. Array indices must be positive integers or logical values.
Error in Lab5_Problem2 (line 25)
val = dataN(:,k);
I cannot figure out why, but I am trying to extract the first row of the array (dataN). Thank you for any help!
0 Kommentare
Antworten (1)
per isakson
am 5 Mai 2020
Bearbeitet: per isakson
am 5 Mai 2020
Three problems:
2 Kommentare
per isakson
am 5 Mai 2020
This should do it
wid = size(dataN,2);
avg = nan( 1, wid );
for k = 1 : wid
val = dataN(:,k);
avg(k) = mean(val);
end
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!