Text as input for function

9 visualizaciones (últimos 30 días)
Hester Krommendijk
Hester Krommendijk el 11 de Mzo. de 2020
Respondida: Ameer Hamza el 11 de Mzo. de 2020
Hi, I need tot write a function 'tjirp' that takes an input 'linear' (so the text). If I do so, I get a parse error saying it's invalid MATLAB syntax. What am I missing?
function [x,info]=tjirp(t,f, 'lineair');
if t > 1
msg = 't moet kleiner zijn dan 1';
error(msg)
end
if 'lineair' == 'kwadratisch'
x = cos(2*pi*f*t.^3/3);
else
x = cos(2*pi*f*t.^2/2);
end
t = 0: 0.1:1;
plot(t, x)
title('Plot van cosinus')
xlabel('tijd')
if f>50
info = fprintf ('samplefrequentie is groot genoeg');
else
info = fprintf ('samplefrequentie is te klein');
end
end

Respuestas (1)

Ameer Hamza
Ameer Hamza el 11 de Mzo. de 2020
When defining a function, you need to write the name of a variable
function [x,info]=tjirp(t,f, str)
Also change the line
if str == 'kwadratisch'
You can pass the value value when calling the function
tjirp(2,1,'linear') % for example

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by