Borrar filtros
Borrar filtros

Loop data in both x and y direction, and do linear fit of each y at each x

58 visualizaciones (últimos 30 días)
Yang Hu
Yang Hu el 11 de Jul. de 2024 a las 15:16
Comentada: Yang Hu el 21 de Jul. de 2024 a las 15:31
I have two matrice. matrix 1 (time points) is 96 by 1 (row is time); matrix 2 is 96 by 150 (attached). matrix 2 is the readout MSD data points at each time point (row) of 150 individual particle (column). I want to fit each MSD data of each particle at increased time point to y=ax+b and so on until the last time point, to get the fitted slope (a). In this way, I can obtain the slope of each particle at increased time points and study their diffusion behavior.
For example: time point 1 has one MSD readout, time point 2 has two MSD readout, time point 3 has three MSD readout. Each of them will generate an x,y line and I wanna find out the fitted slope of the x,y line to y=ax+b.
The matrix 1 can be written as:
time = 15:15:1440; %matrix 1
The result is ideally to be a slope matrix (96 by 150). I have very limited clue on how to do it, appreaciate if anyone know how to do this.
  5 comentarios
Umar
Umar el 11 de Jul. de 2024 a las 19:08
Hi Yang,
Please see response from @Matt J, is this the solution you are seeking regarding your recent comment.
Thanks @Matt J for your contribution and sharing your knowledge, highly appreciated.
Yang Hu
Yang Hu el 11 de Jul. de 2024 a las 20:23
Hi Umar,
I upload actual data point called 'MSDdata' to be more specific. Each row is the readout MSD data at different time points, time interval is 15 - row 1 is the MSD readout at time 15, row 2 is the readout at time 30 and so on.
Row 1 and row 2 MSD data will generate a connected curve with respect to their time points, and this curve will be fitted to y=ax+b to obtain a fitted slope. Due to the data variation, this generated curve will have different slopes over time. I would like to fit y=ax+b to each indidivual particles at increased time points til the end, and continue for all particles.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 11 de Jul. de 2024 a las 20:52
t = 15:15:1440; %time
MSD=readmatrix('MSDdata.xlsx');
A=t.'.^[1,0];
slopes=nan(size(MSD));
for i=1:height(A)
tmp=A(1:i,:)\MSD(1:i,:);
slopes(i,:)=tmp(1,:);
end
whos slopes
Name Size Bytes Class Attributes slopes 96x150 115200 double
  4 comentarios
Matt J
Matt J el 12 de Jul. de 2024 a las 11:05
Yes, Umar is right. That's what it does.

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 11 de Jul. de 2024 a las 18:50
Editada: Matt J el 11 de Jul. de 2024 a las 18:56
Perhaps this is what you want.
matrix1=rand(96,1); matrix2=rand(96,150);
[Xslope,Tslope]=gradient(matrix2,1:150,matrix1);
whos Xslope Tslope
Name Size Bytes Class Attributes Tslope 96x150 115200 double Xslope 96x150 115200 double
  1 comentario
Yang Hu
Yang Hu el 11 de Jul. de 2024 a las 20:32
Hi Matt, thank you for your response. I updated how the data actually are. I want to fit matrix2 (now called MSD data) to increased time points, not the individual time point they are at. For example, MSD data at time point 5 will generate a x,y line with MSD data from time point 1 to 5 at increased time interval (15). So I want to fit this x,y line at increased time points to y=ax+b individually.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by