how can i get different answers?

2 ビュー (過去 30 日間)
arian hoseini
arian hoseini 2022 年 3 月 10 日
コメント済み: Arif Hoq 2022 年 3 月 10 日
i have the following code for example but i also have another (t=1:2) and i dont want write this codde again in another script...is there a way or a function for this i want my code to be as short as possible...thsnk u
L=[1 2 3;4 5 6;7 8 9];
a=L(:,1);b=L(:,2);c=L(:,3);
t=0.5;
r=(a./(b+c))*t;

採用された回答

Arif Hoq
Arif Hoq 2022 年 3 月 10 日
you can write this function
function y=myfunction(L,t)
a=L(:,1);
b=L(:,2);
c=L(:,3);
y=(a./(b+c))*t;
end
then call this function in your script. You need to input L array and t in your script.
clear;
clc;
L=[1 2 3;4 5 6;7 8 9];
t=0.5;
output=myfunction(L,t)
  2 件のコメント
arian hoseini
arian hoseini 2022 年 3 月 10 日
what about t=1:2 it should be two output there first for t=0.5 and second one for t=1:2
Arif Hoq
Arif Hoq 2022 年 3 月 10 日
just put your value in variable t. you will get 2 output here
L=[1 2 3;4 5 6;7 8 9];
t=1:2;
output=myfunction(L,t)
output =
0.2000 0.4000
0.3636 0.7273
0.4118 0.8235

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by