Getting an error message when I use 'triangle()' function.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Baris Dogan
am 24 Mär. 2024
Kommentiert: Dyuman Joshi
am 26 Mär. 2024
I wrote a code to create a tiangle wave form for testing my functions as below:
close all; clearvars; clc;
t = 0:0.01:10*pi;
f = 5;
A = 10;
y = A * triangle(2*pi*t);
figure, plot(y);
But I am getting a Command Window error message as below:
Unrecognized function or variable 'triangle'.
Error in ucgenDalga (line 5)
y = A * triangle(2*pi*t);
I tested the code first in MATLAB 2022b and then in MATLAB Online, having the same error message. When I wrote "help triangle" in Command Window, MATLAB responds an answer. But when I use triangle function in my code, I am receiving the above error. I could not have got an answer from Internet search. Any idea is appreciated.
3 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 24 Mär. 2024
Bearbeitet: Dyuman Joshi
am 24 Mär. 2024
That help is for a Stateflow operator in SIMULINK (as mentioned in the 1st line), not for a function in MATLAB.
help triangle
There is no MATLAB function named triangle (atleast not in the available toolboxes, as not all toolboxes are available in the live editor on MATLAB Answers)
which triangle -all
A = 10;
p = 5;
y = @(x) A*mod(x,p)
fplot(y)
4 Kommentare
Dyuman Joshi
am 26 Mär. 2024
@Baris Dogan, if my answer solved your problem, please consider accepting the answer.
Weitere Antworten (1)
VBBV
am 24 Mär. 2024
Bearbeitet: VBBV
am 24 Mär. 2024
close all; clearvars; clc;
t = 0:0.01:10*pi;
f = 5;
A = 10;
y = A * sawtooth(2*pi*t);
figure, plot(t,y); xlim([0 2*pi])
3 Kommentare
VBBV
am 24 Mär. 2024
Bearbeitet: VBBV
am 24 Mär. 2024
You can modify your code using sawtooth in https://www.mathworks.com/help/signal/ref/sawtooth.html to suit what you want
close all; clearvars; clc;
t = 0:0.01:10*pi;
f = 5;
A = 10;
y = A * sawtooth(2*pi*t,1/2); % triangle wave with two equal sides
figure, plot(t,y); xlim([0 pi])
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!