Writing m function to be read by Livescript

4 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2020 年 5 月 31 日
編集済み: alpedhuez 2020 年 5 月 31 日
In my Livescript called test.mlx, I have variables
days
temperatures
I now want to write a plot
plot(days, temperatures)
But I want to write it as a separate m file
Then, what I did is to write a function m file called plot1.m
function plot1(series1, series2)
plot(series1, series2)
end
Then I put plot1.m in the same directory with test.mlx and modifed test.mlx as
days;
temperatures;
plot_test(days,temperatures)
But it does not seem to work.
  3 件のコメント
alpedhuez
alpedhuez 2020 年 5 月 31 日
編集済み: alpedhuez 2020 年 5 月 31 日
Do not get anything. The function runs on the command line to draw a plot.
alpedhuez
alpedhuez 2020 年 5 月 31 日
It now works. Thank you.

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

採用された回答

madhan ravi
madhan ravi 2020 年 5 月 31 日

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 5 月 31 日
If the name of the main function in a function file and the name of the function file itself are different, MATLAB will know the function by the file name not the function name. So if as you stated you have a file plot1.m containing the text:
function plot_test(series1, series2)
plot(series1, series2)
end
you'll need to call it as plot1(series1, series2). See the Note on this documentation page. [The rule is slightly different for functions in a script file, as also stated in that Note.]
  2 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 5 月 31 日
The original text of the question was like this
Then, what I did is to write a function m file called plot1.m
function plot1(series1, series2)
plot(series1, series2)
end
I guess OP was making some other mistake.
alpedhuez
alpedhuez 2020 年 5 月 31 日
Both are right.

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

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by