How to convert expression to function?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I am trying to convert my expression to a function, but when I remove the informative text I can not call/run the function. How can I fix this?
w=input('Please enter a vector B=[B1 B2 B3]: ');
c2 = [0 B(2) -B(3)];
c3 = [0 -B(2) B(3)];
c2 = B2/norm(B2)
c3 = B3/norm(B3)
disp(' ');
c2=1*B2;
c3=1*-B2;
disp('The following vectors fulfill the demands above:')
disp(' ');
disp(['c2=[' num2str(c2(1)) ',' num2str(c2(2)) ',' num2str(c2(3)) ']'])
disp(['c3=[' num2str(c3(1)) ',' num2str(c3(2)) ',' num2str(c3(3)) ']'])
disp(' ');
I have tried to add the function expression, as follows:
function(c2,c3) = Test(B)
w=input('Please enter a vector B=[B1 B2 B3]: ');
c2 = [0 B(2) -B(3)];
c3 = [0 -B(2) B(3)];
c2 = B2/norm(B2)
c3 = B3/norm(B3)
disp(' ');
c2=1*B2;
c3=1*-B2;
disp('The following vectors fulfill the demands above:')
disp(' ');
disp(['c2=[' num2str(c2(1)) ',' num2str(c2(2)) ',' num2str(c2(3)) ']'])
disp(['c3=[' num2str(c3(1)) ',' num2str(c3(2)) ',' num2str(c3(3)) ']'])
disp(' ');
0 件のコメント
回答 (1 件)
KALYAN ACHARJYA
2019 年 11 月 24 日
編集済み: KALYAN ACHARJYA
2019 年 11 月 24 日
function [c2,c3]=test()
w=input('Please enter a vector B=[B1 B2 B3]: ');
c2 = [0 B(2) -B(3)];
c3 = [0 -B(2) B(3)];
c2 = B2/norm(B2)
c3 = B3/norm(B3)
disp(' ');
c2=1*B2;
c3=1*-B2;
disp('The following vectors fulfill the demands above:')
disp(' ');
disp(['c2=[' num2str(c2(1)) ',' num2str(c2(2)) ',' num2str(c2(3)) ']'])
disp(['c3=[' num2str(c3(1)) ',' num2str(c3(2)) ',' num2str(c3(3)) ']'])
disp(' ');
end
here C2 and C3 as output arduments, if not required, you can avoid them too to just display
8 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interpolation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!