Input data from one array to another
Afficher commentaires plus anciens
Hello. I'm currently trying to implement data from a dataset to a variable, as a function of time. I've tried the answers which are already here, but have been unsuccesful.
Current script:
time=365; % [days] Calculation time
dt=0.1; % [days] Timestep
nt=time/dt; % [-] Calculation steps
tempdata is a [365,2] dataset with an index in column 1 and temperature data in column 2.
for i=2:nt
for j=1:365
T(1)=tempdata(1,2); % Starting condition for T, as i=2:nt
Dt(1)=0; % Time elapsed
Dt(i)=Dt(i-1)+dt;
% I want to set up an if function, which takes the temperature data
% from tempdata(j,2) and puts it into T(i), if Dt(i) is equal to
% tempdata(j,1).
if Dt(i)==tempdata(j,1);
T(i)=tempdata(j,2);
else
T(i)=T(i-1);
end
end
end
This function however doesn't work. I firstly don't understand why, and secondly don't know any other way of doing this. Any of you guys know how?
Much appreciated :)
2 commentaires
Not fully sure what you are trying to do, can you elaborate? From a quick view of your program it should at least run with crashing. Is tempdata(:,1) just 1 to 365? (If this is the case, the program can be simplified greatly)
Just one hint: Dt doesn't seem to depend on the 'j' variable, so you can simply define it once on top:
Dt=0:dt:365;
Same for
T(1)=tempdata(1,2);
Just define it once on top.
Mathias
le 6 Mai 2014
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing 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!