Text as input for function
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Ameer Hamza
2020 年 3 月 11 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!