Why do I get an error when I enter f1(x)?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Helena Karagrigoriou
el 26 de Mzo. de 2016
Editada: Muhammad Usman Saleem
el 28 de Mzo. de 2016
I'm trying to do a MATLAB work sheet using rand and every time I put f1(x) in the command window it says this:
>> f1(x)
Undefined function or variable 'f1'.
Did you mean:
>> f14(x)
Does anyone know why it is saying this?? The only command that I have entered before this is x=rand (not sure if that helps).
PLEASE HELP
2 comentarios
Stephen23
el 26 de Mzo. de 2016
What do you expect f1(x) to do? Have you defined functions or variable with the names f1 and x? If they do not exist (and they are NOT built in MATLAB functions), then of course MATLAB cannot find them and cannot call them.
Please show us the exact code that you are calling.
Gautam Mohan
el 28 de Mzo. de 2016
Hi Helena,
If MATLAB does not have a function definition for the function 'f1', then it will try and suggest the closest matching name, which is 'f14'. It seems like you want to declare a behavior for the f1 function. Information about declaring functions can be found here: http://www.mathworks.com/help/matlab/ref/function.html
I suggest you create a file called f1.m and define the f1 function according to the guidelines in the above link. some sample syntax might look like this:
function out = f1(x)
% MATLAB code goes in here
end
Respuestas (1)
Muhammad Usman Saleem
el 28 de Mzo. de 2016
Editada: Muhammad Usman Saleem
el 28 de Mzo. de 2016
program which are writing is logically flaw. You have generated random no. Which is decimal not integral. While f1(x) means you are gaining f1 variable element located at the index define by x. As x is not integral that why this error is appear.
Let see it
x=rand
x =
0.3304
>> x=round(x)
x =
0
>> f1=[1:5]
f1 =
1 2 3 4 5
f1(x)
Subscript indices must either be real positive integers or
logicals.
Do not use random to assess element of variable f1
0 comentarios
Ver también
Categorías
Más información sobre Variables 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!