Invalid use of operator

89 ビュー (過去 30 日間)
Xeven
Xeven 2022 年 12 月 19 日
コメント済み: Xeven 2022 年 12 月 19 日
Completely new to coding...I put in this
\draw plot[domain=0:7, samples=200] (\x, {0.5*sin(deg(2*pi*\x))});. And Matlab says invalid use of operator what am I doing wrong, it might help if the program would highlight what it doesn't like...Thanks

採用された回答

Fifteen12
Fifteen12 2022 年 12 月 19 日
As Rik mentioned, this is not the correct language. MATLAB (like other programming environments/languages) has a strict syntax that you need to learn in order to use it.
I'm guessing at what you're trying to do, but a valid MATLAB command would be in the form of:
x = linspace(0, 7, 200);
y = 0.5 * sin(2*pi*x);
plot(x, y)
The error invalid use of operater came about because you were using the \ operator in a non-prescribed manner (in a way different than the way MATLAB defines the usage of the \ operator).
If you want to do more than just the simple plot command, then I would echo @Rik's advice to use the Onramp tutorial. It's slow going at first, but with great benefits once you learn it!
  1 件のコメント
Xeven
Xeven 2022 年 12 月 19 日
編集済み: Xeven 2022 年 12 月 19 日
Cool I'll get back in the on ramp. I should have realized the language is different with different applications/programs. I had just opened the Open ai chat gpt app and entered draw a sine wave. It gave the code above. I didn't know where else to try it out except for Matlab. Thanks for the info and help.

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2022 年 12 月 19 日
You need to specify MATLAB in your request to chatbot. Something like "Write a MATLAB program to draw a sine wave" and you should get something like this:
x = linspace(0, 7, 200);
period = pi/2;
y = 0.5 * sin(2 * pi * x / period);
plot(x, y, 'b-', 'LineWidth', 2)
fontSize = 20;
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
title('Sine Wave', 'FontSize', fontSize);
grid on;
  1 件のコメント
Xeven
Xeven 2022 年 12 月 19 日
Awesome thanks for that info!!!(•‿•)

サインインしてコメントする。


Rik
Rik 2022 年 12 月 19 日
移動済み: Image Analyst 2022 年 12 月 19 日
This is not Matlab code. What language is this?
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
  1 件のコメント
Xeven
Xeven 2022 年 12 月 19 日
Open ai chat gpt I forget all these codes aren't universal. Back to the onramp 🐢

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by