interpolation of data takes minutes to operate

1 visualización (últimos 30 días)
Abdulkarim Almukdad
Abdulkarim Almukdad el 27 de Oct. de 2020
Comentada: Mathieu NOE el 27 de Oct. de 2020
I have a data of 5068x59 and I want to interpolate each column with respect to column number 4. I have used the below code and its working fine. However, it takes sometime to operate. Therefore, is there any easier way to perform the below tasks
T=readmatrix('1.xlsx');
x = T(:,4) ;
for b=1:width(T)
for bb=1: length(x)
T1(bb,b)=T(bb,b)+ bb*1E-11; %to make all values unique
end
end
distanceQ = 1:max(T1(:,4)); % new distance vector with step size of 1m
for cc=1:width(T1)
speedQ = interp1(T1(:,4),T1(:,cc) , distanceQ);
filename = 'x)Data.xlsx';
writematrix(speedQ,filename,'WriteMode','append')
end
  5 comentarios
Abdulkarim Almukdad
Abdulkarim Almukdad el 27 de Oct. de 2020
Thanks a lot, that was helpfull. firstly I have changed the loop to the offest function and it works great, as for your what takes most of the time is indeed the writefile function so I have followed what you mentioned to store all the data in 1 variable then to save that variable once as shown below. as for your question, my code is intending to read several files and not all of the files have the same length of data but the difference is just between 1-5 columns. I just have 1 simple questions and I will be very thankfull if you can help me with it. how can I make the result from the interpolation appear in 1 column rather than in 1 row. without using additional transpose functions if possible.
T=readmatrix('1.xlsx');
x = T(:,4) ;
[m,n] = size(T);
offset = 1e-11*((1:m)'*ones(1,n));
T2 = T+offset;
distanceQ = 1:max(T2(:,4)); % new distance vector with step size of 1m
for cc=1:width(T2)
speedQ(cc,:)= interp1(T2(:,4),T2(:,cc) , distanceQ);
end
filename = 'xxx111)Data.xlsx';
writematrix(speedQ,filename,'WriteMode','append')
Mathieu NOE
Mathieu NOE el 27 de Oct. de 2020
hi
glad it helped you
I believe the ouput of the interp1 function is a row vector because distanceQ must also be a row vector
you must change the orientation of distanceQ , by putting distanceQ(:) instead of distanceQ in the interp1 function call
so this should give the correct orientation for speedQ:
speedQ(:,cc)= interp1(T2(:,4),T2(:,cc) , distanceQ(:));

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by