Text as input for function
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Ameer Hamza
am 11 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!