Figure but no plot
古いコメントを表示
The code has no errors but won't show a plot, what am i doing wrong?
clear all, close all, clc
diffmax=100
x=0;0.1;diffmax
plot(f(x))
hold on
xlabel('x')
ylabel('velocity')
axis([0 diffmax 0 30])
function velocity=f(x)
if x>75
velocity = 25;
else
velocity = x/3;
end
end
1 件のコメント
Clara Holmén
2020 年 12 月 2 日
回答 (2 件)
KSSV
2020 年 12 月 2 日
You have not defined f in your code...you need to define f and then call plot...something like this:
diffmax=100
x=0:0.1:diffmax ;
f = @(x) sin(x)
plot(x,f(x))
4 件のコメント
Clara Holmén
2020 年 12 月 2 日
KSSV
2020 年 12 月 2 日
If you have defined an anonymous function (like in the answer), then you have to substitue it to get the function values for the given inputs.
Clara Holmén
2020 年 12 月 2 日
clear all, close all, clc
diffmax=100
x=0:0.1:diffmax
plot(f(x))
hold on
xlabel('x')
ylabel('velocity')
axis([0 diffmax 0 30])
function velocity=f(x)
if x>75
velocity = 25;
else
velocity = x/3;
end
end
KALYAN ACHARJYA
2020 年 12 月 2 日
編集済み: KALYAN ACHARJYA
2020 年 12 月 2 日
Here is the issue, the rest code is perfectly OK
x=0:0.1:diffmax
%..^ ..^ not semicolon, its colon
7 件のコメント
KSSV
2020 年 12 月 2 日
Note that there is no f defined in the code.
KALYAN ACHARJYA
2020 年 12 月 2 日
編集済み: KALYAN ACHARJYA
2020 年 12 月 2 日
Sir, I dont think it is required, as f as function call within plot command. Can you share more please? Thanks
Clara Holmén
2020 年 12 月 2 日
KALYAN ACHARJYA
2020 年 12 月 2 日
編集済み: KALYAN ACHARJYA
2020 年 12 月 2 日
@Clara Replace with colon in your original code, I have tried to answer this "
Figure but no plot
KSSV
2020 年 12 月 2 日
Ohh yes, the function f is defined at the bottom. Just now I am having a look...I have copied only the first few lines..as the problem was in first line.
Clara Holmén
2020 年 12 月 2 日
KALYAN ACHARJYA
2020 年 12 月 2 日
Hope your problem is resolved anyway.
Happy :)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
