How can I increase the speed of the following code with four for loops using other approaches like structure ?
Show older comments
D=dir('*.nc');
ERA_5=[];
for i=1:length(D)
D2=D(i);
name=D2.name;
Lon = ncread(name,"longitude");
Lat = ncread(name,"latitude");
Timee = ncread(name,"time");
T = datetime(1900,1,1) + hours(Timee);
T.Format = 'yyyy-MM-dd';
Wind_u= ncread(name,"u10");%with size =length(loon)* length(laat)* length(day)
Wind_v = ncread(name,"v10");%with size =length(loon)* length(laat)* length(day)
soil_temp = ncread(name,"stl1");%with size =length(loon)* length(laat)* length(day)
T_Precipitation = ncread(name,"tp");%with size =length(loon)* length(laat)* length(day)
for loon=1:length(Lon)
for laat=1:length(Lat)
for day=1:length(T)
T2=T(day);
[ y , m , d ] = ymd( T2);
ERA_5=[ERA_5; Lon(loon) Lat(laat) y m d Wind_u(loon, laat, day) Wind_v(loon, laat, day) soil_temp(loon, laat, day) T_Precipitation(loon, laat, day)];
end
end
end
end
1 Comment
Harsh Saxena
on 10 Jul 2023
Try to use the code option in the editor while adding code to your question. Also, it will be better to if you attach the required files to run the code.
Accepted Answer
More Answers (0)
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!