Getting an error message when I use 'triangle()' function.

조회 수: 4 (최근 30일)
Baris Dogan
Baris Dogan 2024년 3월 24일
댓글: Dyuman Joshi 2024년 3월 26일
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);
Unrecognized function or variable 'triangle'.
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
VBBV
VBBV 2024년 3월 24일
The documentation states this function is for use in Stateflow estimation
Baris Dogan
Baris Dogan 2024년 3월 24일
Thank you for your answer.

댓글을 달려면 로그인하십시오.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 3월 24일
편집: Dyuman Joshi 2024년 3월 24일
That help is for a Stateflow operator in SIMULINK (as mentioned in the 1st line), not for a function in MATLAB.
help triangle
--- help for Stateflow operator triangle --- triangle - Triangle wave test signal triangle(x) generates a triangle wave from the input x based on the equation, Syntax triangle(x) Input Arguments x - Value during test step numeric scalar See also heaviside, ramp, sawtooth, square Introduced in Simulink Test in R2015a Documentation for triangle doc 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
'triangle' not found.
If you want to plot a triangle wave with a given amplitude and period, you can utilize mod -
A = 10;
p = 5;
y = @(x) A*mod(x,p)
y = function_handle with value:
@(x)A*mod(x,p)
fplot(y)
  댓글 수: 4
Baris Dogan
Baris Dogan 2024년 3월 25일
Thank you.
Dyuman Joshi
Dyuman Joshi 2024년 3월 26일
@Baris Dogan, if my answer solved your problem, please consider accepting the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

VBBV
VBBV 2024년 3월 24일
편집: VBBV 2024년 3월 24일
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
Baris Dogan
Baris Dogan 2024년 3월 24일
Thank you for your answer. I also found sawtooth() in my search but I need a triangular (isosceles triangle) signal not a sawtooth (right triangle) signal. Anyway I assumed there may be a ready made function in MATLAB but it seems I need to write my own code.
VBBV
VBBV 2024년 3월 24일
편집: VBBV 2024년 3월 24일
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])

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by