Borrar filtros
Borrar filtros

Not able to understand matlab script

4 visualizaciones (últimos 30 días)
Anshuman S
Anshuman S el 25 de Jul. de 2021
Respondida: Shadaab Siddiqie el 28 de Jul. de 2021
Can someone please help me in understanding this matlab sript in terms of mathematical equation.
N12(2,j)=(N12(1,j)*pa12(1,j)+ dtime*(1/nmol(j)*(alpha1(j)*nL(j)+beta1(j)*na1t*(N12(1,j)-nR(j)))...
+floor(nmolBC(j))/nmol(j)*(beta1R(j)*na1t + beta2R(j)*nb1t)*(N12(1,j)*pa12(1,j)-nR(j)*paR(j))))...
  10 comentarios
Anshuman S
Anshuman S el 26 de Jul. de 2021
Thanks a lot
Steven Lord
Steven Lord el 26 de Jul. de 2021
I agree with Image Analyst's suggestion, though of course with more descriptive variable names than term1, term2, etc. Since people are going to need to try to read and understand this code in the future (potentially including you six months or maybe six days from now) if your code is at all complicated IMO you should err on the side of being descriptive. For example, that first term could be:
interactN1WithR = (m(1)./m(j))*b(j)*N(1)*(N(j)-nsupR(j));
That's still not a great name, but you know what your problem represents better than I do so you could choose an even better name. Though your LaTeX formatted equations seem a bit odd at first glance.
  • Having In some places you refer to m as though it were a vector and in some places as though it were a matrix. That's fine in MATLAB, but if you're referring to just the first row or column of m when you use one index it might be clearer to make that explicit.
  • Your use of both N and n could also be problematic; your finger slipping off the Shift key could change the results of your equations entirely.

Iniciar sesión para comentar.

Respuestas (1)

Shadaab Siddiqie
Shadaab Siddiqie el 28 de Jul. de 2021
From my understanding you want to improve the readability of the code. I agree with @Steven Lord to have more descriptive variable names. You can also leverage MATLAB editor tools to improve code readability. You could use the Apply smart indenting while typing option in the Preferences > MATLAB > Editor/Debugger > Language > Indenting section. You can refer Improve code readability for more information.
As for the existing code I would advise you to refactor the code with above mentioned improvements to make your code more readable.


Más información sobre Loops and Conditional Statements en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by