Multiple Input/output function to excel

4 ビュー (過去 30 日間)
Doorgesh Ramkurrun
Doorgesh Ramkurrun 2020 年 3 月 12 日
コメント済み: Doorgesh Ramkurrun 2020 年 3 月 12 日
Hey Guys,
This is an example of my function:
function[out1,out2,out3,out4]=Trial_4(in1,in2,in3,in4)
  1. I want to know how to input different values for my input 'in2' (for example values for in2 ranges from 0 to 0.1 with intervals = 0.001) without having to input them repeatedly in the command window,
  2. Secondly, I want to know how to convert my outputs into a table which can then be used in Excel.
Thanks!

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 12 日
編集済み: Ameer Hamza 2020 年 3 月 12 日
You can try something like this
in1 = 0;
in2 = (0:0.001:0.1)';
in3 = 0;
in4 = 0;
% if out1 out2 out3 out4 are scalars
out1 = zeros(size(x));
out2 = zeros(size(x));
out3 = zeros(size(x));
out4 = zeros(size(x));
for i=1:numel(in2)
[out1(i),out2(i),out3(i),out4(i)]=Trial_4(in1,in2(i),in3,in4);
end
Then to save in MS excel file
writematrix([out1, out2, out3, out4], 'filename.xlsx');

その他の回答 (1 件)

Jakob B. Nielsen
Jakob B. Nielsen 2020 年 3 月 12 日
編集済み: Jakob B. Nielsen 2020 年 3 月 12 日
You can achieve this in many ways. The simplest way would be to just create arrays of your input ranges, for example
in2=0:0.001:0.1;
will get you a 1x101 array with values from 0, in increments of 0.001, to 0.1. And then do this for all your inputs. As long as your function Trial_4 can handle elementwise operations (put dots in front of multiplications and powers and such, so instead of in2^2 write in2^.2), then your outputs will also be 1x101 arrays.
In regards to a table, you can either do
table(out1,out2,out3,out4);
and then copy/paste it over from the workspace.
Or simply / more elegantly,
xlswrite('output.xlsx',out1,out2,out3,out4);
  1 件のコメント
Doorgesh Ramkurrun
Doorgesh Ramkurrun 2020 年 3 月 12 日
Hey Jakob,
Thanks, worked like a charm.
Cheers!

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by