Text as input for function
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
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
0 comentarios
Ver también
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects 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!