How to operate on multiple function outputs?

1 回表示 (過去 30 日間)
Matt
Matt 2014 年 5 月 16 日
回答済み: Matt 2017 年 11 月 29 日
Take this as an exmaple
t = [0.997020539 -0.07615956 0.0122; -0.076640022 -0.996018987 0.04553; 0.008683887 -0.046323856 -0.99888];
x = dcm2angle(t, 'XYZ') * 180 / pi
x =
177.344786261912
This is the first value only. I can get what I want by doing the following.
[x(1) x(2) x(3)] = dcm2angle(t,'XYZ'); x = x * 180 / pi
x =
Columns 1 through 2
177.344786261912 0.49755632844709
Column 3
4.39562805575083
I want a way to do something like x = [dcm2angle(t, 'XYZ')] * 180 /pi;
Any ideas? I tried the above, with {} and deal(), none did the trick.

採用された回答

Matt
Matt 2017 年 11 月 29 日
I found a workaround. Hopefully someone will come here and find a better option. I wrapped the dcm2angle function in another function that combines the output. Basically this:
function [out] = Mydcm2angle( T, sequence )
[out(1), out(2), out(3)] = dcm2angle(T, sequence);
end
Then the output can be used as:
result = Mydcm2angle(t, 'XYZ') * 180 / pi;

その他の回答 (1 件)

the cyclist
the cyclist 2014 年 5 月 17 日
x = cell(1,3);
[x{:}] = dcm2angle(t, 'XYZ') * 180 / pi;
  2 件のコメント
Matt
Matt 2014 年 5 月 19 日
Using version 2013a this throws an error.
[x{:}] = dcm2angle(t,'XYZ') * 180 / pi
Error using /
Too many output arguments.
Adding .* and ./ did not correct the error. Runnig just the RHS gives:
dcm2angle(t,'XYZ') * 180 / pi
ans =
177.344765026818
Modifying the RHS slightly:
dcm2angle(t,'XYZ') .* (180/pi)
ans =
177.344765026818
Still does not produce multiple outputs.
the cyclist
the cyclist 2014 年 5 月 20 日
Hm. Just to be clear, you did the preallocation step?
x = cell(1,3);
Maybe try
x = cell(3,1);
Also, I don't have the Aerospace Toolbox, so I was only going by the online documentation, and then created my own function as follows:
function [x,y,z] = answerTest()
x = 1;
y = 2;
z = 3;
end
and then calling
x = cell(1,3);
[x{:}] = answerTest()

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

カテゴリ

Help Center および File ExchangeGet Started with Aerospace Blockset についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by