So this doesn't work if either of the t = 0:0.2:2 OR t = linspace(0,2,100); are commented or not.
How do I get it to work since the turorial sheet says that this exact code should work if I run:
[a,b,c] = ThreeFunc2(i1,i2,i3)
But it doesnt.
It gives the error:
Unrecognized function or variable 'i1'.

 채택된 답변

the cyclist
the cyclist 2023년 10월 15일

0 개 추천

The variables i1, i2, and i3 in the function call
[a,b,c] = ThreeFunc2(i1,i2,i3)
or the variables t, f1 and f2 in the function call
[a,b,c] = ThreeFunc2(t,f1,f2)
need to be defined before the function call, not just exist within the function. Those variables are expected as inputs.

댓글 수: 4

Dan Giffin
Dan Giffin 2023년 10월 15일
편집: Dan Giffin 2023년 10월 15일
Hi,
Thanks for the response.
Sadly that doesn't seem to be what the exercise is wanting from me unless I'm misunderstanding you/the exercise.
This doesn't seem to be defining anything but it implies that this code should be enough.
(I've called mine ThreeFunc2 because ThreeFunc was my first attempt that didn't work either)
Dyuman Joshi
Dyuman Joshi 2023년 10월 15일
You have defined the function correctly, but in order to get the output, you have to provide the inputs and call the function, as The Cyclist has mentioned as well.
Through the command window, define the values t, f1, f2 or i1, i2, i3 with any set of values, and call the function with those variables, as stated in the question as well (the line under the rectangle in the image).
the cyclist
the cyclist 2023년 10월 15일
Your assignment explicitly states, "the time vector you specified in parameter i1", in other words you need to tell your function what i1 is.
The assignment is admittedly less clear on what to do with i2 and i3 (although it does say you can use a number for i3).
Dan Giffin
Dan Giffin 2023년 10월 15일
Riiight, that makes a lot of sense.
Thanks for your time,
sorry for being slow.

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

추가 답변 (1개)

Sam Chak
Sam Chak 2023년 10월 15일

1 개 추천

I think you can do something like this:
t = 0:0.01:10;
f1 = 1/10;
f2 = 1/5;
% Call the function
ThreeFunc2(t, f1, f2)
% Write the tasks to be carried function
function ThreeFunc2(t, f1, f2)
y1 = sin(2*f1*pi*t);
y2 = cos(2*f2*pi*t);
plot(t, [y1' y2']), grid on
end

카테고리

도움말 센터File Exchange에서 Entering Commands에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2023년 10월 15일

댓글:

2023년 10월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by