How would I convert a script to a function?
Mostrar comentarios más antiguos
I have just made a script randArrGen.m that generates an array of n floating point numbers, which needs to be used as a function within another scipt, but I'm struggling to understand how to turn it into a function. In my head it seems easier just to run this script within the other script when required. The a and b values aren't massively important and are just to give a range for the floating point numbers to be within (I though -1000 and 1000 were good boundaries).
% randArrGen generates an array of n floating point numbers, where n is a
% value inputted by the user.
n = input("How many values do you wish to have in the array?");
a = -1000;
b = 1000;
array = (b-a).*rand(n,1) + a;
Respuesta aceptada
Más respuestas (1)
Jan
el 7 de En. de 2021
All you have to do to convert it to a function, is to add a head line:
function array = randArrGen
Maybe you want to define n and/or a, b as input arguments?
1 comentario
Louise Wade
el 7 de En. de 2021
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!