Create mfile for a loop function

1 vue (au cours des 30 derniers jours)
Reem RA
Reem RA le 21 Juil 2022
Commenté : Reem RA le 22 Juil 2022
I was wondering if it is possible to create a function in mfile format for the bellow code (b0_T03_s is a table):
% to find x velocity and x position for bike #0
for i= 0:1:23;
b0_T03_s(2+i,25) = b0_T03_s(1+i,25) + b0_T03_s(1+i,23);
b0_T03_s(2+i,24) = b0_T03_s(1+i,24) + b0_T03_s(1+i,25) + (0.5*b0_T03_s(1+i,23));
end
  2 commentaires
Abderrahim. B
Abderrahim. B le 21 Juil 2022
HI!
Do you mean to convert this snap of code into a MATLAB function?
Reem RA
Reem RA le 21 Juil 2022
yes exactly

Connectez-vous pour commenter.

Réponses (1)

Cris LaPierre
Cris LaPierre le 21 Juil 2022
Yes, it's possible. See this page on creating live functions in a live script using the Refactor tool.
The orginal and refactored code must be live scripts (.mlx file type) to use this tool, but once created, you can save as *.m if necessary.
  6 commentaires
Cris LaPierre
Cris LaPierre le 22 Juil 2022
You will need to keep in mind varible scope. Function only have access to the variables passed in as inputs or that are created inside the function.
Reem RA
Reem RA le 22 Juil 2022
Thanks a lot Cris.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by