Index exceeds matrix dimensions Error.
Afficher commentaires plus anciens
Hi!
I'm working on a script and while it works with smaller vectors, I can't get it to work with the one I need it to work with which is considerably larger.
Index exceeds matrix dimensions.
Error in avalanchePredictor (line 31)
dist(i) = sqrt((weather(i,4) - current(1))^2 + (weather(i,5) -
current(2))^2 + (weather(i,6) - current(3))^2 + (weather(i,7) -
current(4))^2);
This is the exact error message that I'm getting and below is the code line 31 is around for reference.
dist = zeros(1, 100000);
weather = importdata('weather.csv');
for i = 1:11434
dist(i) = sqrt((weather(i,4) - current(1))^2 + (weather(i,5) - current(2))^2 + (weather(i,6) - current(3))^2 + (weather(i,7) - current(4))^2);
end
for i = 1:11434
fprintf(fid,'%10.0f %10.0f %10.0f %10.3f \n', weather(i,(1:3)), dist(i));
end
fid = fclose('all');
As I said, I think I'm trying to loop it for too long or something (I'm not very good at MATLAB to begin with...), and I tried following some fo the suggested steps, but to no avail. Can anybody help me out?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Weather and Atmospheric Science dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!