using subfunctions in a script to find area of rectangle..

16 ビュー (過去 30 日間)
Austin
Austin 2013 年 11 月 13 日
コメント済み: Jan 2018 年 9 月 13 日
below is my scripts and sub functions, why do i still get this error when all my subfunctions and script already have the green light button.
Script:
[length,width]=readlengthwidth;
printlengthandwidth(length,width)
Function1:
function [l,w] = readlengthwidth
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
l=input('please input your desired length');
w=input('please input your desired width');
end
Function2:
function printlengthandwidth(length,width)
fprintf('your desired length is %.2f\n',length)
fprintf('your desired width is %.2f\n',width)
fprintf('therefore your desired area will be %.2f\n',area)
end
function3:
function [area] = calcarea(length,width)
area=length*width;
end

回答 (1 件)

Matt J
Matt J 2013 年 11 月 13 日
編集済み: Matt J 2013 年 11 月 13 日
Not sure what the "green light button" means or which error you're referring to (I see none posted). However, you cannot use subfunctions inside a script. Make the mfile a function file.
  1 件のコメント
Jan
Jan 2018 年 9 月 13 日
Since R2016b scripts are allowed to contain subfunctions.

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

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by